How to destroy an object with table listeners?

Hi,
Acoording to section http://developer.anscamobile.com/content/application-programming-guide-graphics-and-drawing#Removing_Objects_Properly
to remove an object we should either call removeSelf() and =nil

local rect=display.newRect(100,100,50,50)  
rect.vx=0.5  
rect.vy=0.5  
  
function rect:frame()  
 self:translate(self.vx, self.vy)  
end  
Runtime:addEventListener("frame", rect)  
  
function rect:remove()  
 self:removeSelf()  
 self=nil  
end  
  
timer.performWithDelay(5000, function()  
 rect:remove() end)  
  
Runtime:addEventListener("enterFrame", function()  
 Runtime:dispatchEvent{name="frame"}  
 end)  

code above represents an object with a “frame” listener which remains active after the object has been set to nil. This situation causes an error when trying to “translate”

Anybody knows how remove function of the object should be in order to avoid this situation?

Thanks! [import]uid: 76413 topic_id: 23867 reply_id: 323867[/import]

Remove the event listener before removing the object.

function rect:remove() self:removeEventListener("frame", self) self:removeSelf() self=nil end [import]uid: 44647 topic_id: 23867 reply_id: 96206[/import]

ok but set to nil doesn’t delete all the table properties?
What does “self=nil” stand for then?

Thanks [import]uid: 76413 topic_id: 23867 reply_id: 96275[/import]