Calling transition.pause() and then transition.cancel()

Simply put, calling transition.pause followed by transition.cancel and then respawning an object causes a memory leak. Am I missing something?

Calling just transition.cancel works great, but I would prefer to give the user the option to reset from a pause menu, for example.

local function draw() local rect1 = display.newRect( display.contentCenterX, display.contentCenterY, 200, 200) rect1.trans = transition.blink( rect1, { time=5000 } ) local function reset() transition.pause(rect1.trans) transition.cancel(rect1.trans ) rect1.trans = nil display.remove(rect1) rect1 = nil draw() end rect1:addEventListener( "tap", reset ) end --INIT: draw() ----- ----- local monitorMem = function() collectgarbage() local memCount = collectgarbage("count") / 1024 if (prevMemCount ~= memCount) then if memCount \< 1.00 then print( "MemUsage: " .. memCount\*1024 .. "KB") prevMemCount = memCount elseif memCount \>= 1.00 then print( "MemUsage: " .. memCount .. "MB") prevMemCount = memCount end end local textMem = system.getInfo( "textureMemoryUsed" ) / 1000000 if (prevTextMem ~= textMem) then if textMem \< 1.00 then print( "TextureMemUsage: " .. textMem\*1024 .. "KB") prevTextMem = textMem elseif textMem \>= 1.00 then print( "TextureMemUsage: " .. textMem .. "MB") prevTextMem = textMem end end end Runtime:addEventListener( "enterFrame", monitorMem )

A short delay timer & .resume solves it.

Use this reset function :

 local function reset() transition.pause(rect1.trans) local function afterTimer() transition.resume() transition.cancel() rect1.trans = nil rect1:removeSelf() -- display.remove(rect1) rect1 = nil draw() end timer.performWithDelay( 10, afterTimer ) end

Thank you.  

But, the issue still remains. Why can’t one cancel transitions that are in a paused state, and then redraw an item without a leak occurring?

Any ideas?

I could resume all transitions before canceling, but that seems odd as the docs clearly state that it’s possible to cancel paused transitions.  

Sorry to press this issue, but I’m not sure if this is a bug, or an error on my part. Any clues?

I’m back! I’ve renewed my pro subscription!

Can you build a small sample app that shows the process and the leak?

Here. See attached. Just click the square and check the output.

P.S. It doesn’t matter whether you call transition.pause() or .cancel() with or without params. 

Please add your config.lua and build.settings to the zip file and use the FIle and Bug at the top of the page.  Looks like transition.pause() might need investigated.  This will get it on the engineering schedule.

Rob

Done. Thanks for your help. I submitted this bug quite a while ago, I hope this second submission is noticed!

Current Case#: 32567

While I have you, is it ever necessary, when calling a function to precede it with a local variable?  (say, “local draw = draw()” in the above example) ?

The example you listed will create a variable named draw that is scoped to it’s containing block of code (i.e. if you did it inside an “if” statement, it’s only visible to the block inside the if statement, if you did it inside a function, it’s only visible to that function, etc.).  The contents of that variable will be the value returned by the draw() function.  Your draw function above doesn’t return anything, so your variable named draw will contain nil.

Rob

Alright, that makes sense. 

A related question:  

Say “draw()” is actually a function meant for spawning display objects, and it returns said display objects.  Within the draw function, the display objects are localized properly into a table.

However, draw is called from another generic function, and draw() is not preceded by a variable. 

Must I worry about the 1st instance of draw, even though its returned objects are already localized someplace else?

local spawns = {} local function draw() --I create an object, --assign and localize it to a table index, and --return end local function start() --other stuff-- draw() -- is this call safe, i.e. it won't create a global/cause a leak? end

If you do not capture the returned value, the local variable will be cleared, but allocated memory attached to it wont and you end up loosing a handle to that memory and you wont be able to free it up.

So yes, not capturing that first object is a problem.

Rob

A short delay timer & .resume solves it.

Use this reset function :

 local function reset() transition.pause(rect1.trans) local function afterTimer() transition.resume() transition.cancel() rect1.trans = nil rect1:removeSelf() -- display.remove(rect1) rect1 = nil draw() end timer.performWithDelay( 10, afterTimer ) end

Thank you.  

But, the issue still remains. Why can’t one cancel transitions that are in a paused state, and then redraw an item without a leak occurring?

Any ideas?

I could resume all transitions before canceling, but that seems odd as the docs clearly state that it’s possible to cancel paused transitions.  

Sorry to press this issue, but I’m not sure if this is a bug, or an error on my part. Any clues?

I’m back! I’ve renewed my pro subscription!

Can you build a small sample app that shows the process and the leak?

Here. See attached. Just click the square and check the output.

P.S. It doesn’t matter whether you call transition.pause() or .cancel() with or without params.