Memory Management

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
Hydrolek99
Prole
Posts: 4
Joined: Sun Jun 04, 2017 9:38 pm

Memory Management

Post by Hydrolek99 »

Hello. I was wondering how would one go about removing an image/graphic from a Love Program? Like a background or sprite that is no longer needed in a game anymore.I really do not want to have my game take up a huge amount of memory due to images/Sprites that have no purpose. Would I be able to delete them if I were to put them in a table then remove them when they are no longer needed or is there another way of doing it?
After doing some looking around, I have found out about garbage collection and a Love.discard function.
would any of those help me out? If so how exactly?
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Memory Management

Post by zorg »

I never heard of love.discard myself, and i'm not sure if the lua collectgarbage function would free up space taken up by graphics, since those are on the C++ side; still, if you don't have any lua variable pointing to a resource, löve would eventually free those automatically, so this is not something you should worry about. (running collectgarbage after freeing stuff might work, but again, unless you're absolutely sure you need to do that, you probably shouldn't)
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
CaptainMaelstrom
Party member
Posts: 161
Joined: Sat Jan 05, 2013 10:38 pm

Re: Memory Management

Post by CaptainMaelstrom »

I'll second what zorg has said.

to create an image:

Code: Select all

image = love.graphics.newImage(filepath)
to delete

Code: Select all

image = nil
The actual memory will be freed up sooner or later (up to Lua's garbage collection implementation)
User avatar
Hydrolek99
Prole
Posts: 4
Joined: Sun Jun 04, 2017 9:38 pm

Re: Memory Management

Post by Hydrolek99 »

Ok. That seems simple enough. Thank you. :-)
So all I would need to do to free up space is tell the garbage collection to do it somewhere in my code?
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Memory Management

Post by zorg »

Hydrolek99 wrote: Sat Jul 22, 2017 7:17 am Ok. That seems simple enough. Thank you. :-)
So all I would need to do to free up space is tell the garbage collection to do it somewhere in my code?
Yes, you can force it by calling collectgarbage, but even without that, the resources will be freed automatically, sooner or later.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 2 guests