From Xojo Documentation
Jump to: navigation, search

Executed automatically when a class goes out of scope.




The Destructor method is called automatically, so you would never call it yourself. It takes no parameters and does not return a value.

Destructors are typically used to do any "clean up" that is not done for you automatically. If it exists, a class's destructor is called automatically when an instance of the class is deleted or goes out of scope — for example, when the user closes the window.

To create the Destructor for a custom class, add a method to the class and name it "Destructor".

Destructors are called when the last reference to an object is removed, even if execution is in a destructor for another object. Note that this means you can cause a stack overflow if your destructor triggers other destructors in a deep recursion. However, such overflow will not happen as long as properties of the object are being cleaned up automatically. So, it is generally preferable to not set properties to Nil in your destructor, but instead let them be cleaned up for you.

Unlike a Constructor or other methods, the Destructor in a subclass does not override its superclass Destructor. Normally you would not call Super.Destructor in your subclass' Destructor since this will cause the superclass' Destructor to fire twice.

See Also

Constructor method; Destructors Can't Have Parameters error.

Personal tools

Starting Out
Dig Deeper
More Help