Do coroutines eventually get terminated by Lua when not in use? Or do I have to stop them myself

I want to fire a function that contains two loops, both individually wrapped in a coroutine. I want these loops to run at the same time. I later intend on breaking these loops, but the coroutines will still exist.

I want to repeat this process over and over so I can only run the loops when necessary, but that means more coroutines will be created.

My friend says that Lua should take care of any dormant coroutines after a while, but I didn’t want to leave that to chance. What should I do?


There’s a discussion about this here:

And according to this post, they’re garbage collected as long as they’re finished (not processing anything or yielding) and there are no references to them. Roblox have their own threading implementation apparently, and it doesn’t seem to have been made clear anywhere (by Roblox staff) exactly when or what conditions are necessary for it to be garbage collected, if at all.

Seeing as there are no methods to kill a coroutine and ensure that it’s been garbage collected, I recommend continuing as you’ve set out to do. If you notice it’s causing a memory leak after the threads have stopped and it’s causing issues then I’d report it as a bug.


Was wondering this the other day. Thanks. :+1:

1 Like