Lua memory increases with Director Class scene changes - is that normal?

I'm using the director class, and being VERY careful to remove all objects, timers, transitions, listeners, and everything else once I'm done. But my Lua memory is jumping around a lot. Should it be identical (once I move away from a scene, then return to it)? Texture memory always returns to the same level, that's just fine.

Here's the weird behaviour:

CASE 1: If I transition from the mainmenu.lua to my level1.lua, then back and forth a lot, texture memory is perfect (always returns to same level), and Lua memory is the same too.

CASE 2: if I create and destroy many objects repeatedly in level1.lua, then return to mainmenu.lua, the Lua memory goes up a few hundred bytes (texture memory stays the same). Then if I load level1.lua again but don't create/destroy anything, just exit right away, the Lua memory goes down a bit (but not to the same level).

CASE 3: If I create and destroy many objects in level1.lua, then return to mainmenu.lua, then go back to level1.lua and create/destroy again, then keep repeating that, I can get the Lua memory to increase 2-3kB. But then it jumps back down! Then gradually starts climbing again... but never gets higher than 2-3kB from its initial point.

I noticed the director class (v1.3) demo does the same thing - Lua memory sometimes stays the same, sometimes goes up, keeps going up a few kB, then jumps back down.

Is this normal? I've been working for hours to try to clean everything up, but now I'm wondering if that's even possible...

I'm using this code at the end of the "clean" function for my "level1.lua":

1
2
3
4
5
6
7
8
        -- collect garbage
        collectgarbage( "collect" )
        
        -- print memory usage
        local memUsage_str = string.format( "memUsage = %.3f KB", collectgarbage( "count" ) )
        print( memUsage_str )
        local texMemUsage_str = string.format( "texMemUsage = %.3f KB", system.getInfo( "textureMemoryUsed" ) )
        print( texMemUsage_str )

I know nothing of the various versions of director, but I believe there were problems with the cleanGroups() routine in the past, it not freeing up all memory.

Off the top of my head that's the only thing I can really think of for now.

Did you try freeing the memory of your modules?
Check my post on the subject: here

I believe director does that automatically when the transitions are finished.

I've done some more testing, and I've found it's related to timers. They don't seem to all get cancelled and have their memory freed instantly.

I wrote a function in my program that loads a level, creates and destroys objects thousands of times, then returns to the main menu. Then it does that procedure automatically 100 times. I look at the memory during each iteration.

When I have display objects with physics and touch listeners, Lua memory is perfectly stable every iteration. But as soon as I add timers, the memory jumps around as I described - moves up and down around some point (in my case around 400kB), but doesn't keep going up.

Interestingly, once the auto-test is complete, and I wait a couple of seconds, then check the memory again, the memory jumps WAY down (in my case, around 150kB).

So it seems there's no memory leak, just that cancelling or garbage collection takes a while with timers. Which makes it annoying to test for memory leaks, since I need to use an auto-testing function and run it many times to make sure it settles.

Im glad i came across your post because im having the same issue, i keep thinking im not removing something because everytime i check my memory used it jumps around like crazy.

views:1718 update:2011/10/13 9:25:17
corona forums © 2003-2011