[RESOLVED] ImageSheet not releasing texture memory

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]

@cyberparkstudios, this is interesting. Thank you for posting your finding. I initially thought it was because it takes a while before it clears out after forcing the garbage collection, but your runtime comparison suggests that may not be the case. So I’d like to hear more thoughts on this.

Meanwhile, will you place your code inside < code > and < / code > (without spaces), which will make your code much easier to read. You can edit your original thread by clicking on the Edit text link at the very bottom below the Post a Reply section.

Naomi

Edit: It looks like Walter answered your question with clear explanation. Nice. Here’s the link to his reply post:

http://developer.coronalabs.com/forum/2012/06/21/problem-garbage-collection-spritesheet#comment-140908 [import]uid: 67217 topic_id: 35461 reply_id: 140911[/import]

Thanks Naomi

Walter’s explanation is spot on to that problem.

[RESOLVED] [import]uid: 148857 topic_id: 35461 reply_id: 140917[/import]

@cyberparkstudios, this is interesting. Thank you for posting your finding. I initially thought it was because it takes a while before it clears out after forcing the garbage collection, but your runtime comparison suggests that may not be the case. So I’d like to hear more thoughts on this.

Meanwhile, will you place your code inside < code > and < / code > (without spaces), which will make your code much easier to read. You can edit your original thread by clicking on the Edit text link at the very bottom below the Post a Reply section.

Naomi

Edit: It looks like Walter answered your question with clear explanation. Nice. Here’s the link to his reply post:

http://developer.coronalabs.com/forum/2012/06/21/problem-garbage-collection-spritesheet#comment-140908 [import]uid: 67217 topic_id: 35461 reply_id: 140911[/import]

Thanks Naomi

Walter’s explanation is spot on to that problem.

[RESOLVED] [import]uid: 148857 topic_id: 35461 reply_id: 140917[/import]