tefozi
tefozi

Reputation: 5480

Method that gets called just before object destroyed

Is there method that gets called just before object destroyed? So I can override it.

Like

protected override function beforeDestuction():void
{
    trace("This object is about to be destroyed!");
}

Upvotes: 0

Views: 1474

Answers (4)

Luis B
Luis B

Reputation: 1722

One way to know whether an object will be garbage collected is to hold references in a Collection to all the objects that you allocate memory for. Then when you want the GC to destroy them, then take them out of the Collection. When you take them out of the collection, call your method "beforeGarbageCollection" or "beforeDestruction"; hopefully soon (but no guarantees) the GC will pick up the unreferenced object and destroy it.

Let me know if this is suitable.

Upvotes: 0

Robert Bak
Robert Bak

Reputation: 4236

This won't apply to all objects, but when looking at components that extend UIComponent, the 'remove' event can be somewhat usefull, assuming there are no other strong references to a removed object it should be garbage collected.

UIComponent.html#event:remove

Upvotes: 0

Marcus Stade
Marcus Stade

Reputation: 4984

No, there are no destructors in actionscript, unfortunately.

Upvotes: 2

sharvey
sharvey

Reputation: 8155

If by destroyed you mean getting garbage-collected, then I don't think there's an event or a Object method for that.

Upvotes: 0

Related Questions