Unable to free texture memory (Spritesheet)

Hi!

This can seem weird, but after I solved a system memory leak issue, I just discover that I had now a texture memory leak. Actually, the texture memory keep going up from page to page and reach dramatic number when I play throught multiple level of my game.

I know that my Spritesheet actually take a lot of memory, so I try to remove them in the exitScene() (I use storyboard), but the spriteSheet:dispose() actually do nothing.

Here how I created the spritesheet:
[lua]local screen = display.newGroup()
local runningSheet, jumpSheet , dashSheet , throwSheet , hitSheet

function scene:createScene( event )

local group = self.view

runningSheet = sprite.newSpriteSheet( “player/courir_v4-x2.png”, 316, 276)
jumpSheet = sprite.newSpriteSheet( “player/saut_v3-x2.png”, 316, 276)
dashSheet = sprite.newSpriteSheet( “player/dash_v1-x2.png”, 316, 276)
throwSheet = sprite.newSpriteSheet( “player/lancer_v1-x2.png”, 316, 276)
hitSheet = sprite.newSpriteSheet( “player/tombe_v1-x2.png”, 316, 276)
victorySheet = sprite.newSpriteSheet( “player/victory-x2.png”, 315, 276)

local spriteSet = sprite.newSpriteMultiSet(
{
{ sheet = runningSheet, frames = { 1,2,3,4,5,6,7,8,9,10,11,12} },
{ sheet = jumpSheet, frames = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18} },
{ sheet = dashSheet, frames = { 1,2,3,4,5} },
{ sheet = throwSheet, frames = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18} },
{ sheet = hitSheet, frames = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16} },
{ sheet = victorySheet, frames = { 1,2,3,4,5,6,7,8} },
})

sprite.add(spriteSet, “running”, 1, 12, 700, 0)
sprite.add(spriteSet, “jumping”, 13, 7, 150, 1)
sprite.add(spriteSet, “dash”, 31, 5, 100, 0)
sprite.add(spriteSet, “throw”, 36, 18, 200, 1)
sprite.add(spriteSet, “hit”, 54, 16, 600, 1)
sprite.add(spriteSet, “victory”, 70, 8, 600, 1)

player = sprite.newSprite(spriteSet)

screen:insert(player)

group:insert(screen)

end[/lua]

And that how I tried to remove them:

[lua]function scene:exitScene( event )

runningSheet:dispose()

–jumpSheet:removeSelf()
jumpSheet:dispose()

–dashSheet:removeSelf()
dashSheet:dispose()

–throwSheet:removeSelf()
throwSheet:dispose()

–hitSheet:removeSelf()
hitSheet:dispose()

–victorySheet:removeSelf()
victorySheet:dispose()

end[/lua]

Is there something I’m doing wrong? Why cant I remove the texture memory from the spritesheet?

Thank you! [import]uid: 181680 topic_id: 33632 reply_id: 333632[/import]

Set each on to nil after dispose. [import]uid: 40033 topic_id: 33632 reply_id: 133706[/import]

Thank for your answer, but sadly, I’ve forgot to say that I’ve already try this…

[lua] runningSheet:dispose()
runningSheet = nil

jumpSheet:dispose()
jumpSheet = nil

–dashSheet:removeSelf()
dashSheet:dispose()
dashSheet= nil

throwSheet:dispose()
throwSheet = nil

hitSheet:dispose()
hitSheet = nil

victorySheet:dispose()
victorySheet = nil[/lua]

Putting “= nil” actually do nothing!
Seriously, I truly do not understand how the texture memory can go so high, without being able to lower it between scene! I’ve dispose the spritesheet, set them to nil, what else can I do? [import]uid: 181680 topic_id: 33632 reply_id: 133707[/import]

@alex_gareau, I dispose all of my imageSheets/spriteSheets after I manually remove all display objects that use the sheets. I believe you can not clear out the sheets from memory if an object that uses the sheet still exists. I’m not sure if it’s the cause of your issue, but you may want to consider manually disposing all display objects that are linked to the sheets before you dispose the sheets themselves and see if it makes any difference.

Naomi [import]uid: 67217 topic_id: 33632 reply_id: 133709[/import]

Thank you both for your answer, i’ve finaly manage to control the texture memory leak. I’ve been working on it all day and it’s a mix of yours answer and this:

[lua]local function cleanChildren(group)
for i=group.numChildren,1,-1 do
if(group[i]) then
if(group[i].numChildren) then
cleanChildren(group[i])
else
group[i]:removeSelf()
group[i] = nil
end
end
end
group:removeSelf()
group = nil
end
cleanChildren(scene.view)[/lua]

With this, I’m now fully able to erase the texture memory from scene to scene!

Thank You! [import]uid: 181680 topic_id: 33632 reply_id: 133737[/import]

Cool. Glad to hear you’ve sorted this out.

Cheers,
Naomi [import]uid: 67217 topic_id: 33632 reply_id: 133751[/import]

Set each on to nil after dispose. [import]uid: 40033 topic_id: 33632 reply_id: 133706[/import]

Thank for your answer, but sadly, I’ve forgot to say that I’ve already try this…

[lua] runningSheet:dispose()
runningSheet = nil

jumpSheet:dispose()
jumpSheet = nil

–dashSheet:removeSelf()
dashSheet:dispose()
dashSheet= nil

throwSheet:dispose()
throwSheet = nil

hitSheet:dispose()
hitSheet = nil

victorySheet:dispose()
victorySheet = nil[/lua]

Putting “= nil” actually do nothing!
Seriously, I truly do not understand how the texture memory can go so high, without being able to lower it between scene! I’ve dispose the spritesheet, set them to nil, what else can I do? [import]uid: 181680 topic_id: 33632 reply_id: 133707[/import]

@alex_gareau, I dispose all of my imageSheets/spriteSheets after I manually remove all display objects that use the sheets. I believe you can not clear out the sheets from memory if an object that uses the sheet still exists. I’m not sure if it’s the cause of your issue, but you may want to consider manually disposing all display objects that are linked to the sheets before you dispose the sheets themselves and see if it makes any difference.

Naomi [import]uid: 67217 topic_id: 33632 reply_id: 133709[/import]

Thank you both for your answer, i’ve finaly manage to control the texture memory leak. I’ve been working on it all day and it’s a mix of yours answer and this:

[lua]local function cleanChildren(group)
for i=group.numChildren,1,-1 do
if(group[i]) then
if(group[i].numChildren) then
cleanChildren(group[i])
else
group[i]:removeSelf()
group[i] = nil
end
end
end
group:removeSelf()
group = nil
end
cleanChildren(scene.view)[/lua]

With this, I’m now fully able to erase the texture memory from scene to scene!

Thank You! [import]uid: 181680 topic_id: 33632 reply_id: 133737[/import]

Cool. Glad to hear you’ve sorted this out.

Cheers,
Naomi [import]uid: 67217 topic_id: 33632 reply_id: 133751[/import]