Memory & Texture Memory Questions

OK, I'm in the middle of making my game and I have the following screens:

-Main Menu
-Settings
-Level Select
-Level 1

In the main.lua file I have the following function to monitor the memory and texture memory in use:

1
2
3
4
5
6
7
8
9
10
local monitorMem = function()
 
        collectgarbage("collect")
        print( "\nMemUsage: " .. collectgarbage("count") )
        local textMem = system.getInfo( "textureMemoryUsed" ) / 1000000
        print( "TexMem: " .. textMem )
 
end
        
local memTimer = timer.performWithDelay(1000, monitorMem, -1)

Assuming you are using the Storyboard API for scene changes?

If so, it all depends on whether or not you are purging the previous scene or removing it.

The small climb in memory every time you switch a scene is most-likely due to the fact that when a new module is loaded, there's a reference to it created in the global package.loaded table.

When you first went to Level Select screen and then back to the Main Menu and saw a 13kb jump, that is most-likely due to the fact that the module is still loaded in memory (even if all the display objects have been removed—which explains why texture memory went back down to norma—and everything in the module has been completely cleaned out).

With storyboard, the only way to completely unload a module (including its reference in package.loaded) is to use storyboard.removeScene()).

Currently, there is a bug where storyboard.removeScene() does NOT remove the reference from package.loaded, but in the next Daily Build (after 2011.689), the issue has been fixed.

The real test you want to do is this - if you cycle back and forth between main menu and level select (or any two scenes) does the memory continue to climb?

It's likely that you're just seeing a one-time bump in memory, whether it be an improperly unloaded scene as Jonathan suggests, or something else. But if you can flip back and forth without constant increase, you should be fine.

Test each combination, then see if just flipping around between scenes over and over causes continual climb.

Hi Jonathan,

Yes, I am of course using the Storyboard API - that's probably the reason why the Texture Memory usage is being so well managed throughout.

As you can see, I just have this problem with with the Memory Usage climbing.

When I have been experimenting, trying to rectify this, I switched to calling storeboard.removeAll() in every scene to completely unload any that may have been previously loaded. I thought that the issue with the package.loaded bug had been resolved in the latest build (2011.689). Is this bug still present in this build then?

Also, to remove any external modules from package.loaded do I do the following within exitScene():

1
package.loaded["timerModule"] = nil

@iNSERT.CODE: The storyboard.removeAll() fix will be in the Daily Build *after* 2011.689, so that *could* be your problem, BUT, that wouldn't explain why memory usage goes up 6kb every time you go through everything.

When I switch back and forth between different scenes with the Storyboard SampleCode (which will also be included in the next daily build, after 2011.689), I'm not seeing the memory usage continue to climb (past a certain point, its always bouncing back and forth between a few ranges), so the culprit has to be within your code somewhere.

Also, due to delays with garbage collection in Lua, I found that it's better to have your memory usage counter in an enterFrame listener at the bottom of main.lua, that way you can monitor realtime memory usage (see the Storyboard samplecode, main.lua).

@jonathanbeebe: Thanks for getting back again. I'll continue to look through my code to find where the problem lies and wait for the next build to see if that helps any too.

With regard to removing external modules, is what I'm doing in the previous post correct?

Also, a what point (in terms of Memory Usage) would a device lag and/or crash? Say, an iPhone 4?

views:1527 update:2011/11/25 8:45:21
corona forums © 2003-2011