Garbage Collecting Unnamed Channels

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
parallax7d
Citizen
Posts: 82
Joined: Wed Jul 02, 2014 11:44 pm

Garbage Collecting Unnamed Channels

Post by parallax7d » Sat Nov 05, 2016 7:58 pm

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?

User avatar
raidho36
Party member
Posts: 1802
Joined: Mon Jun 17, 2013 12:00 pm

Re: Garbage Collecting Unnamed Channels

Post by raidho36 » Sat Nov 05, 2016 8:38 pm

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.

User avatar
slime
Solid Snayke
Posts: 2820
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Garbage Collecting Unnamed Channels

Post by slime » Sat Nov 05, 2016 8:40 pm

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.

Post Reply

Who is online

Users browsing this forum: Jugbot and 4 guests