Does this rotate object code snippet need a transition.cancel? (i.e. will it leak memory)

Does this rotate object code snippet need a transition.cancel?  (i.e. will it leak memory)

If it does require a “cancel” to be perfect, where/how would you do this here?

-- image is a display object local function rotateImage()     local tc\_temp = transition.to( image, { time=time, rotation=image.rotation+100, onComplete=rotateImage } ) end rotateImage()  

I’m asking noting I’ve read that one should really get handles to the transitions and timers, and make sure you cancel them.

Hi Greg,

I don’t think this will cause any memory leak, but to be safe, you could “attach” the transition to the object itself, then you’ll know that you’re using the same reference for the transition in each repeat of it.

Brent

Hi Brent - just re understanding things:

  • does this imply you really don’t need to use a “transition.cancel” at all for transitions re memory management? i.e. it’s just there to functionally stop a transition when you want to?

  • if there were a memory leak say, then assigning the new transition created each loop wouldn’t solve this would it, as you would be creating a new transition object each time, then losing the handle to the previous one?

Hi Greg,

Yes, transitions should clear themselves from memory after completion, as long as you haven’t force-locked them into some global variable or something odd like that. But, I often find it easier to make the transition as a parameter of the object itself, so I always know its reference and I can manage it that way.

Brent

Tags can be helpful in that situation as well.

http://docs.coronalabs.com/api/library/transition/to.html#params.tag-optional

thanks @develephant - hadn’t noticed this feature - should be very useful

Hi Greg,

I don’t think this will cause any memory leak, but to be safe, you could “attach” the transition to the object itself, then you’ll know that you’re using the same reference for the transition in each repeat of it.

Brent

Hi Brent - just re understanding things:

  • does this imply you really don’t need to use a “transition.cancel” at all for transitions re memory management? i.e. it’s just there to functionally stop a transition when you want to?

  • if there were a memory leak say, then assigning the new transition created each loop wouldn’t solve this would it, as you would be creating a new transition object each time, then losing the handle to the previous one?

Hi Greg,

Yes, transitions should clear themselves from memory after completion, as long as you haven’t force-locked them into some global variable or something odd like that. But, I often find it easier to make the transition as a parameter of the object itself, so I always know its reference and I can manage it that way.

Brent

Tags can be helpful in that situation as well.

http://docs.coronalabs.com/api/library/transition/to.html#params.tag-optional

thanks @develephant - hadn’t noticed this feature - should be very useful