I am using ImageSheet api
I create an image from the ImageSheet
I attach a touch event listener to the image
When it is time to get rid of the image, I remove the listener, and nil the image
I then ‘nil’ the ImageSheet … BUT TEXTURE MEMORY IS NOT RELEASED
I test for texture memory before and after these actions and it stays the same. (see sample code below).
Is there something else I need to do to release that texture memory that ImageSheet is holding on to??
HOWEVER, if I run the same exact code, but make the touch listener on Runtime instead of on the image, it DOES indeed clear the texture memory.
So the problem is with assigning the event listener to the image itself. Is this a bug? Or is there another step I need to take to see that the ImageSheet properly releases that texture memory?
SAMPLE 1 - with event listener on the image object - does not release memory
local options = { width = 100, height = 100, numFrames = 9, sheetContentWidth = 300, sheetContentHeight = 300}
local sheet = graphics.newImageSheet( "numSheet300.png", options )
local s = display.newImage( sheet, 1 )
print( system.getInfo( "textureMemoryUsed" ) )
local function clearIt(e)
if e.phase == "ended" then
s:removeEventListener("touch", clearIt)
s:removeSelf()
s = nil
collectgarbage( "collect" )
print( system.getInfo( "textureMemoryUsed" ) ) --\> 1048576
sheet = nil
collectgarbage( "collect" ) --\> STILL 1048576
print( system.getInfo( "textureMemoryUsed" ) ) --\> 1048576
end
end
s:addEventListener("touch", clearIt)
SAMPLE 2 - event listener on Runtime - (does release the memory
local options = { width = 100, height = 100, numFrames = 9, sheetContentWidth = 300, sheetContentHeight = 300}
local sheet = graphics.newImageSheet( "numSheet300.png", options )
local s = display.newImage( sheet, 1 )
print( system.getInfo( "textureMemoryUsed" ) )
local function clearIt(e)
if e.phase == "ended" then
Runtime:removeEventListener("touch", clearIt)
s:removeSelf()
s = nil
collectgarbage( "collect" )
print( system.getInfo( "textureMemoryUsed" ) ) --\> 1048576
sheet = nil
collectgarbage( "collect" ) --\> CLEARS THE MEMORY
print( system.getInfo( "textureMemoryUsed" ) ) --\> 0
end
end
Runtime:addEventListener("touch", clearIt)
I really like the ImageSheet … it is a great tool and does some very good things, and I have it at the core of what my app is doing, so I need to find a way to fix this memory leak.
Thanks! [import]uid: 148857 topic_id: 35461 reply_id: 335461[/import]