Page 1 of 1

Memory Management in Lua

Posted: Sun Apr 01, 2012 7:30 pm
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. :)

Re: Memory Management in Lua

Posted: Sun Apr 01, 2012 7:49 pm
by Robin
To be honest, I see no problem. Memory fluctuations happen, you only need to worry if it starts to explode.

Re: Memory Management in Lua

Posted: Sun Apr 01, 2012 8:32 pm
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?

Re: Memory Management in Lua

Posted: Sun Apr 01, 2012 8:50 pm
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

Re: Memory Management in Lua

Posted: Sun Apr 01, 2012 9:03 pm
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:

Re: Memory Management in Lua

Posted: Sun Apr 01, 2012 9:26 pm
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