Does task.spawn automatically get garbage collected?

What I mean by the title is, if for example the function that I made with task.spawn returns a value, will the task.spawn automatically get garbage collected.?

Yes, once the function returns or errors, the coroutine enters dead status, and eventually gets garbage collected under the condition that no variable is strongly refering to it.

task.spawn(function() return end) -- no reference
local thread = task.spawn(function() return end) -- reference
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.