Memory Management in Lua

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
arbaces
Prole
Posts: 6
Joined: Sun Mar 25, 2012 6:44 pm

Memory Management in Lua

Post by arbaces »

Hi friends,

I've started working on a game with Love2d recently with no prior experience using Lua. I am writing this post hoping that you can help me to understand how Lua deals with memory leaks before I add too many leaks to my game. =)

I primarily develop on my PC which runs Windows 7. To monitor memory usage, I am looking in the "Windows Task Manager" under "Memory (Private Working Set)" My assumption is that the memory used by Love2D is the memory used by my program and that when garbage collection frees memory, the listed amount will decrease.

So I start the game and do nothing while waiting for the memory usage reach equillibrium. When this happens after about 20 seconds the game has a memory usage of 26,808 K. I then rapidly press the 'i' key 15 times. The 'i' key turns the music off or starts it again when pressed. After doing this, the memory usage is 45,940 K.

Is this a memory leak? If so, could you help me to understand what's causing it? Most of my code is in the gameHandler.lua program. I handle sound using TESound.lua. (I call TESound.cleanup() with each update, so that should clean up music which has been stopped, right?)

Thanks in advance for any help. :)
Attachments
ravenLOVE.love
(2.83 MiB) Downloaded 160 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Memory Management in Lua

Post by Robin »

To be honest, I see no problem. Memory fluctuations happen, you only need to worry if it starts to explode.
Help us help you: attach a .love.
arbaces
Prole
Posts: 6
Joined: Sun Mar 25, 2012 6:44 pm

Re: Memory Management in Lua

Post by arbaces »

Hi,

Thank you for your reply. :)

My concern is this isn't just a fluctuation in memory usage.

If I spam the 'i' key for 2-3 minutes, the memory usage climbs up to 1,001,808 K (a gig!). If I wait and do nothing, the memory stays where it is. If the sound files were correctly freed, shouldn't the memory Love2d is using fall back to less than 30 M again?
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: Memory Management in Lua

Post by Xgoff »

yeah forced collections aren't getting rid of anything significant

i noticed tesound creates a new sound object for each play, so it's possible dead sounds are still getting referenced somewhere, which would keep the gc from freeing them

could also be a memory leak in love itself but i would think something like that would have been noticed long ago

EDIT: nope the sounds are getting collected
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Memory Management in Lua

Post by Boolsheet »

That is in fact a memory leak. It's fixed for the next version though.

You can't do much about it in 0.7.2 sadly.
Xgoff wrote:noticed long ago
Right. :oops:
Shallow indentations.
User avatar
Xgoff
Party member
Posts: 211
Joined: Fri Nov 19, 2010 4:20 am

Re: Memory Management in Lua

Post by Xgoff »

Boolsheet wrote:That is in fact a memory leak. It's fixed for the next version though.

You can't do much about it in 0.7.2 sadly.
Xgoff wrote:noticed long ago
Right. :oops:
well that explains it
Post Reply

Who is online

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