Transition and memory leaks, concerning objects removed before a transition completes

I’m curious how transitions handles objects that are removed before the transition is completed.

Seems like best practice would to remove any transitions before removing the object. If an object has multiple transitions this can get tricky.

If an object has been removed before a transition, acting the object, has completed, will transition cancel that transition just continue trying to set properties on nil?

It’s possible to organize transition references in an array and cancel them before removing an object. But, if transition has some built in mechanism to handle this it was some extra code.

I’m just looking for best practice advice. [import]uid: 98652 topic_id: 27107 reply_id: 327107[/import]

Here’s a quick experiment. That shows some interesting effects of using transition.

If an object is removed, with display.remove( object ), the object disappears from the screen, But it seems Transition keeps a reference to the object and continues to the set the properties of the object. When the transition is complete, the onComplete is called and properties of the, supposedly removed, object are still accessible at which point the object is removed again.

The memory display seems to say that there is memory leak. Memory seems to top out and stay steady after a point.

[lua]local function Box()
local box = display.newRect( 0, 0, 64, 64 )
box:setFillColor( math.random(0,255), math.random(0,255), math.random(0,255) )
return box
end
local function remove_box( box )
print( “remove”, box.name )
display.remove( box )
end

local function touch_box( event )
print( “**** touch box”, event.target.name )
display.remove( event.target )
end

local count = 0

local function make_box()
local box = Box()
box.x = math.random(32, 288)
box.y = -32

count = count + 1
box.count = count
box.name = “box”…count

box:addEventListener( “touch”, touch_box )

transition.to( box, {y=512, time=5000, onComplete=remove_box} )
end

timer.performWithDelay( 1200, make_box, -1 )


local memory_text = display.newText( “Hello”, 5, 5, native.systemFont, 16 )
memory_text:setTextColor( 255, 0, 0 )
memory_text.x = display.contentCenterX

local monitorMem = function()
collectgarbage()
local textMem = math.round( system.getInfo( “textureMemoryUsed” ) / 1000000 )
memory_text.text = “Mem:”…math.round( collectgarbage(“count”)) … " tex:"… textMem
end

Runtime:addEventListener( “enterFrame”, monitorMem )[/lua] [import]uid: 98652 topic_id: 27107 reply_id: 110065[/import]