Composer scene managment memory issue

Hi guys,

I have a problem when moving from level.lua back to menu.lua: level.lua memory is not nilled (level.lua scene is not destroyed properly I assume).

So in level.lua “scene:create” I have this chunk of code:

local Sprites = require("sprite") -- REQUIRE SPRITE DEFINITIONS FROM sprite.lua file local myGroup= display.newGroup() function createPlayers( ) local sprite = Sprites[math.random(#Sprites) local tmp = display.newSprite( myGroup, sprite.image\_sheet, sprite.sequence\_data ) tmp.x = math.random(100, 200); tmp.y = math.random(100, 200) physics.addBody( tmp, "dynamic", {density=1, bounce=0.1, friction=.2} ) return tmp end

Then later call (spawn) as:

createPlayers() 

In level.lua scene:hide I have removed (nil) all audio, all groups, all “require” variables… like this:

display.remove(myGroup)
myGroup = nil

display.remove(sceneGroup)
sceneGroup= nil

Sprites = nil

I did not only removed display objects touch, enterFrame and events listeners, but that is not necessary because I removed all display objects.

In menu.lua scene:show I have removed level scene via:

composer.removeScene(level)

I have no other problems except memory, everything works without errors.

When I start game in menu.lua I measure 0.8MB of texture memory used.
Then I navigate to level.lua and I measure 50MB. It stays flat (does not increase over time).

When I navigate back to menu.lua I measure 44MB…
And then when I go for the second time to level.lua I measure 50MB again…

Why I never reach 0.8MB measured at starting point (is this normal composer behaviour)? 

Waiting your reply! :slight_smile:
Many thanks.

Ivan

Right off the bat, you don’t want to  require anything within the scene: functions. It is always best to require your modules at the top of your Composer scenes. In addition, calling 

Sprites = nil

isn’t really doing anything substantive for your memory management, as calling  local Sprites means that, when you dispose of that scene, the reference to that  Sprites module is destroyed. 

You should look over the Corona Composer game template on github to see how Composer handles scenes and moving from one to another. Also, going over the Corona doc for performance and memory management is always a good idea, even if just for reference.

Good luck!

I will look over it again !
Thanks Alex! :slight_smile:

Hi Alex…
Problem was specific afterall (if you wish you can see my newest post).

local Sprites at the top was not cleared from memory by Composer…

Thanks.
Ivan

Right off the bat, you don’t want to  require anything within the scene: functions. It is always best to require your modules at the top of your Composer scenes. In addition, calling 

Sprites = nil

isn’t really doing anything substantive for your memory management, as calling  local Sprites means that, when you dispose of that scene, the reference to that  Sprites module is destroyed. 

You should look over the Corona Composer game template on github to see how Composer handles scenes and moving from one to another. Also, going over the Corona doc for performance and memory management is always a good idea, even if just for reference.

Good luck!

I will look over it again !
Thanks Alex! :slight_smile:

Hi Alex…
Problem was specific afterall (if you wish you can see my newest post).

local Sprites at the top was not cleared from memory by Composer…

Thanks.
Ivan