You are here :

Sub nodes

Recent changes
Site plan

A destructor is called whenever an instance is destroyed.

A primitive variable is destroyed when it goes to end of scope. A reference variable is destroyed when the last reference stops pointing to it.

Syntax :

 destructor() {
   // code

Example :

 public class SomeClass {
   destructor() {
     Console.out << "SomeClass.destructor called


   static public sub main(const string# args) {
     SomeClass sc = new SomeClass(); // call default constructor
     sc = null; // sc stops pointing to created reference => calls destructor
     SomeClass sc2 = new SomeClass();
     sc = sc2;
     sc2 = null; // sc still points on the instance
   } // end of scope, sc is destroyed. Thus it stops pointing at instance => calls destructor
Propulsed by Wiclear