display.remove() not working correctly

at lease not in my code
i have 63 images that need to be removed and redrawn i check memory before and after the remove function when the images are redrawn they use more memory then was removed
[blockcode]
function fnFallReDraw()
print(“fnFallReDraw”)

if timer2 then
timer.cancel( timer2 )
timer2 = nil
end
if trans4 then
transition.cancel( trans3 )
transition.cancel( trans4 )
trans3, trans4 = nil, nil
end
for a = 1, 63 do
if gamePeice[a] then
print( “removing…gamePeice[”…a…"]")
js.memCheck()
display.remove(gamePeice[a])
gamePeice[a] = nil
end
end

fnShowBoard()
end
[/blockcode]
the fnShowBoard function redraws the images which is the same function that draws them the first time but each time its using about 10KB more memory. not texture memory texture memory remains the same after the redraw [import]uid: 7911 topic_id: 15314 reply_id: 315314[/import]

Why do you not try the simpler method on line 17

gamePiece[a]:removeSelf()

this should also remove the handlers, etc associated (if any) not sure if the display.remove does that or not.

and on line 14, why do you not try the explicit if gamePiece[a] ~= nil then

Another thing is the transition, again try the explicit ~=nil just to be sure, as that could respawn or not release the memory depending on what you are doing with the transition.

have a look, and let us know how it went.

BTW, what is js.memCheck, that seems like your own library than JavaScript :wink:

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 15314 reply_id: 56589[/import]

You are iterating forward from index 1 to 63 to delete objects from the table. Doing it this way actually only deletes every other object!

Here’s what’s happening: first time through the loop it deletes the first object in the table. Second time through it deletes the second object in the table, which used to be the 3rd object before you started deleting. And the 1st object (which used to be the 2nd) is never deleted! Going through the table like this will leave you with about half as many objects still in your table, undeleted.

The solution is simply to iterate backwards through the table:

for a = 63, 1, -1 do
–delete object at table[a]
end

That loops through the objects in the table from 63 to 1 in steps of -1 which WILL delete all objects in the table, assuming there are 63 objects to begin with.

[import]uid: 9422 topic_id: 15314 reply_id: 56608[/import]

@jay
i made the changes you suggested but no change is hard to see the exact problem from the little bit of code posted if you dont mind i could send you the project to look at so you could better see the problem just too much code to post
@xenonbl
i also made your changes but still have the memory leak
[import]uid: 7911 topic_id: 15314 reply_id: 56616[/import]