It is normally not necessary to implement the class destructor as AngelScript will by default free up any resources the objects holds when it is destroyed. However, there may be situations where a more explicit cleanup routine must be done as part of the destruction of the object.
The destructor is declared similarly to the constructor, except that it must be prefixed with the ~ symbol (also known as the bitwise not operator).
class MyClass { // Implement the destructor if explicit cleanup is needed ~MyClass() { // Perform explicit cleanup here } }
Observe that AngelScript uses automatic memory management with garbage collection so it may not always be easy to predict when the destructor is executed. AngelScript will also call the destructor only once, even if the object is resurrected by adding a reference to it while executing the destructor.
It is not possible to directly invoke the destructor. If you need to be able to directly invoke the cleanup, then you should implement a public method for that.