necessity of removing event listener

hi all,
when should I really remove an event listener?
suppose this case:
[lua]local function remove__me(event)–remove after animation
if event.phase == ‘end’ then
–do I need to call remove event listener here?event.sprite:removeEventListener(“sprite”, remove_me)
event.sprite:removeSelf()
–perhaps if I do event.sprite = nil?
end
end
level_up_sprite.x, level_up_sprite.y = -5,0
level_up_sprite:addEventListener(‘sprite’, remove_me)
level_up_sprite:playClip(‘levelup’)[/lua]

do I really need to call remove event listener for that sprite removal function, because it will be removed anyway?

Thank you.

[import]uid: 11334 topic_id: 4765 reply_id: 304765[/import]

From what I understand it won’t crash your app if you don’t remove a floating event listener that is not attached to an object but it will take up memory and cycles. Repeated adding of the same event listener without removal might cause a crash at some point. So… you don’t “have to” but you “should”.

I keep track of my event listeners in a table so I can reference them and delete them easily. That way when I switch screens I can automatically remove all objects within the view and events that are associated with it.

EDIT: Sorry I forgot to directly answer your question… If you nil an object it doesn’t remove the event listener - they are separate. You can remove the event listener before or after you nil the object. [import]uid: 11393 topic_id: 4765 reply_id: 15232[/import]

yeah it won’t crash my app instantly but it will cause memory leak (perhaps i’m using this term liberally) I want to know whether calling removeSelf also automatically removes the event listener associated with it, because if not, the correct way of removing display objects would be to removeeventlistener, removeself, and then nil the object itself if it has user defined data. Is this correct? [import]uid: 11334 topic_id: 4765 reply_id: 15233[/import]

If you nil an object it doesn’t remove the event listener - they are separate. You can remove the event listener before or after you nil the object. [import]uid: 11393 topic_id: 4765 reply_id: 15235[/import]

I understand that, I am questioning whether I need to remove event listener after removeSelf not nilling it. [import]uid: 11334 topic_id: 4765 reply_id: 15236[/import]

Logically I would remove the listener before removing/nilling the object but I don’t think it matters.
[import]uid: 11393 topic_id: 4765 reply_id: 15237[/import]