Can't Dispose of a SpriteSheet (new API) in Storyboard. Texture Memory Leak

Here is the backstory.

I was using the old method of sprite sheets in StoryBoard.

And in order to dispose of a sprite sheet, it was simple as:

myspriteSheet:dispose()

This released the sprite sheet from textured memory and everything was fine: (thanks to Peach Pellen) here:

http://forums.coronalabs.com/topic/24243-resolved-dispose-of-a-sprite-sheet-in-storyboard/?hl=%2Bdispose+%2Bsprite+%2Bstoryboard
 

Now that I have converted to the (new api), I am getting the following message when trying to dispose of my sheets.

In new API this:

myspriteSheet:dispose()

Results this error:

attempt to index up value ‘babyduckSheet’ <a userdata value>

Below is a “basic” block flow of what I am doing now, and in the “exit scene” is where I have the dispose.

Now…I did find this in the forums:

http://forums.coronalabs.com/topic/21176-cannot-dispose-newimagesheet-object-properly-new-sprite-api/?hl=%2Bdispose+%2Bsprite

The post suggests to do this now:

babyduck:removeSelf()

babyduck = nil

babyduckSheet = nil

Which seems to resolve my sprite sheets being removed now from textured memory but I thought I would ask if I am doing something wrong with the new API or if there is a better way than using Garbage Collector to clean up spritesheets in the new API? 

Thank you for your time.

[lua]local babyduckData,babyduckSheet,babyduckSeqData,babyduck,babyduckTouch

– Called when the scene’s view does not exist:
function scene:createScene( event )
local screenGroup = self.view

–setup SpriteSheet new API method
babyduckData = { width=220, height=197, numFrames=3, sheetContentWidth=660, sheetContentHeight=197 }
babyduckSheet = graphics.newImageSheet( “assets/page07/page07-babyduck-sprite.png”, babyduckData )
babyduckSeqData = {{ name = “babyduckPlay”, frames = {1,2,3,1}, time=2000, loopCount = 1 }}
babyduck = display.newSprite( babyduckSheet, babyduckSeqData )
babyduck.x = display.contentWidth/2+130
babyduck.y = display.contentHeight/2+150
babyduck:setSequence( “babyduckPlay” )
babyduck.touch = babyduckTouch
end

– Called when scene is about to move offscreen:
function scene:exitScene( event )
–stop animations
babyduck:pause()

–remove sprite sheets
babyduckSheet:dispose()
end
[/lua]

Hi @chakorules,

There is no more “dispose” call for the new image sheet method. Just nil’ing out its reference should be enough, and the garbage collector will take care of the rest. If you still get the “upvalue” error, then it’s a scoping issue in your Storyboard setup, most likely.

Best regards,

Brent

Hi @chakorules,

There is no more “dispose” call for the new image sheet method. Just nil’ing out its reference should be enough, and the garbage collector will take care of the rest. If you still get the “upvalue” error, then it’s a scoping issue in your Storyboard setup, most likely.

Best regards,

Brent