Quick question: Discarding unused resources?

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
Suppercut
Prole
Posts: 18
Joined: Sun Aug 05, 2012 4:10 pm

Quick question: Discarding unused resources?

Post by Suppercut »

How would I unload graphics or sounds? Does the garbage collector do it (as in setting all its reference indices to nil so it becomes unused)?
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Quick question: Discarding unused resources?

Post by slime »

Yep, if there are no more references to an object, then the garbage collector will take care of it eventually. If you want it to happen immediately, you can force a couple garbage collection cycles with: collectgarbage() collectgarbage().
User avatar
Suppercut
Prole
Posts: 18
Joined: Sun Aug 05, 2012 4:10 pm

Re: Quick question: Discarding unused resources?

Post by Suppercut »

And this will remove the resource itself from memory, not just the object associated with it? So if I remove all references to an Image or Canvas, eventually the graphics card memory will be freed?
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Quick question: Discarding unused resources?

Post by slime »

Yep, as long as other LÖVE functions don't hold references to it. For example if an Image is used by a SpriteBatch then it won't be completely deleted at least until the SpriteBatch is deleted as well.
User avatar
Suppercut
Prole
Posts: 18
Joined: Sun Aug 05, 2012 4:10 pm

Re: Quick question: Discarding unused resources?

Post by Suppercut »

Alright, thanks mate! :D
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot], Majestic-12 [Bot] and 7 guests