Being new to Gideros and Lua, I have always thought that there is automatic garbage collection (similar to Java), so I do not ever have to call collectgarbage() in my code. I found out, however, that my app was leaking memory. When I tracked memory usage by calling collectgarbage("count") in an EnterFrame event handler, I saw that memory usage was building up and never freed. I added an explicit collectgarbage() call in a timer loop periodically and the memory leak went away. Am I doing something wrong?
Also, when I tested calling collectgarbage() inside EnterFrame event handler, my movieclip animations stopped working. Once I removed the collectgarbage() call, my animations started playing again. Is this expected behavior? Why would collectgarbage() affect movie clips?
I still have a lot to learn.
Comments
Maybe problem is that memory is not freed right away, only after some time?
If you use class level or global variables as references then the item being referenced will still remain referenced until those globals are assigned new values - often this means that a lot of data is kept "hanging around" even though it's been finished with as it's technically still referenced.
If you want to be totally obsessive about your garbage it's not a bad idea to explicitly set class or global variables to a nil value as soon as you've finished with the data as that gives the GC a better chance to know what's actually garbage.
Just my $0.02
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
Likes: ar2rsawseen, techdojo
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
1. Try to allocate small number of objects/tables, preferably reuse them.
2. Call collectgarbage() at the beginning of a level, at the end of a level and at the pause menu.
3. Also, on iOS, we automatically call collectgarbage() (twice) when there is a memory warning.
Likes: techdojo, avo
In my current framework - I actually call collectgarbage() when I transition from screen to screen, maybe this is a bit of overkill, but it also helps to ensure I have no leaks (see what I mean about obsessive )
Likes: atilim
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
So my thought is do it first rather than last.
---------------------------------------