Page 1 of 1

Garbage Collecting Unnamed Channels

Posted: Sat Nov 05, 2016 7:58 pm
by parallax7d
Lets say in theory I'm spawning/using tens or hundreds of thousands of channels, what's the best way to ensure the garbage collector is doing it's thing?

For named channels, just :clear and dereference them, done.

But how about for unnamed channels? Does the thread that spawned the channel have to :clear it? Will they automatically destruct if there is nothing in their queue, since no references exist for them? Or do they stick around as long as something might want to use them? Would it be best to stick with named channels since they can be explicitly destroyed?

Re: Garbage Collecting Unnamed Channels

Posted: Sat Nov 05, 2016 8:38 pm
by raidho36
Channels get garbage collected the same way other objects do. As soon as you let go of the last reference to the channel, GC is free to collect it and destroy all data in it.

Re: Garbage Collecting Unnamed Channels

Posted: Sat Nov 05, 2016 8:40 pm
by slime
parallax7d wrote:But how about for unnamed channels? Will they automatically destruct if there is nothing in their queue, since no references exist for them?
Unnamed channels stick around until there are no Lua-side references, even if they still have stuff in their Queue. Named channels stick around until there are no Lua-side references and they have nothing in their queue. That said, creating tens or hundreds of thousands of Channels doesn't sound like a great idea - I recommend reusing Channels as much as possible.