Destroying Objects
It is generally the case that after an object is used, it is removed from memory to make room for other programs or objects to take that object's place. In order for this to happen, a destruction method is called upon that object. Destroying an object will cause any references to the object to become invalid.
A destructor is a method called when an instance of a class is deleted, before the memory is deallocated. Note that in C++, a destructor can not be overloaded like a constructor can. It has to have no arguments. A destructor does not need to maintain class invariants.
In garbage collecting languages, objects may be destroyed when they can no longer be reached by the running code. Examples of this are Python and Java. Python has destructors, and they are optional. In many garbage collecting languages, finalizers (which are called before an object is garbage-collected) are used instead of destructors, since the point of garbage-collection is not predictable in these languages. Example of these include Java and Ruby.
Read more about this topic: Object Lifetime
Famous quotes containing the words destroying and/or objects:
“Frankly, I do not like the idea of conversations to define the term unconditional surrender. ... The German people can have dinned into their ears what I said in my Christmas Eve speechin effect, that we have no thought of destroying the German people and that we want them to live through the generations like other European peoples on condition, of course, that they get rid of their present philosophy of conquest.”
—Franklin D. Roosevelt (18821945)
“The cart before the horse is neither beautiful nor useful. Before we can adorn our houses with beautiful objects the walls must be stripped, and our lives must be stripped, and beautiful housekeeping and beautiful living laid for a foundation.”
—Henry David Thoreau (18171862)