Re: Memory Leak in only two lines
Posted: Mon May 05, 2014 1:44 am
Thanks everyone for the help, I wasn't expecting such an amazing response time!
I was just worried because I usually program in C++ and I handle my own garbage collection, I guess that caused some trust issues when moving to easier, more user friendly languages like Lua.
I let the program run a bit (and using collectgarbage( 'collect' ) after every draw cycle) and it never went over a specific amount of MB of RAM.
I am using userData in the love physics module so I might be misusing it probably, are there any basic house keeping tips I should know about with using them? How are they any different from storing a table as a member inside any other table?
I was just worried because I usually program in C++ and I handle my own garbage collection, I guess that caused some trust issues when moving to easier, more user friendly languages like Lua.
Anyway I see what you mean by the garbage collector letting memory usage pile up before clearing it all,Azhukar wrote:If you have a leak of few mb per second in your code it is not caused by the 2 lines you provided.Some things that can cause higher memory upkeep:Code: Select all
for i=1,10000 do love.graphics.setColor(255, 255, 255, 255) love.graphics.rectangle("fill", 10, 10, 100, 100) end
Userdata - creating new userdata every frame. This includes image objects among other things.
Tables - all inaccessible tables are eventually collected, if you create a lot of them per frame it can add up and the garbage collector will spend a lot of time keeping up and you will notice higher memory upkeep.
Note neither of these are leaks since the garbage collector takes care of most dumbassery you throw at it, including memory islands. In case you're working with love.physics or other framework modules it is possible to make the collector cry and hide things inside userdata objects which it will not clean up, such as the setUserData() method in some physics objects.
Unless your program crashes due to insufficient memory over time, it's likely your code just produces a lot garbage on the side.
I let the program run a bit (and using collectgarbage( 'collect' ) after every draw cycle) and it never went over a specific amount of MB of RAM.
I am using userData in the love physics module so I might be misusing it probably, are there any basic house keeping tips I should know about with using them? How are they any different from storing a table as a member inside any other table?