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?
Memory Management
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Memory Management
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 True 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.
- CaptainMaelstrom
- Party member
- Posts: 161
- Joined: Sat Jan 05, 2013 10:38 pm
Re: Memory Management
I'll second what zorg has said.
to create an image:
to delete
The actual memory will be freed up sooner or later (up to Lua's garbage collection implementation)
to create an image:
Code: Select all
image = love.graphics.newImage(filepath)
Code: Select all
image = nil
- Hydrolek99
- Prole
- Posts: 4
- Joined: Sun Jun 04, 2017 9:38 pm
Re: Memory Management
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?
So all I would need to do to free up space is tell the garbage collection to do it somewhere in my code?
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Memory Management
Yes, you can force it by calling collectgarbage, but even without that, the resources will be freed automatically, sooner or later.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?
Me and my stuff True 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.
Who is online
Users browsing this forum: Ahrefs [Bot] and 1 guest