
Destructors And Cleaning Up An Instance: Object-Oriented Design
When we get to the end of our use of a class instance, we need to clean up after ourselves. This is where destructors come into play. They are similar to constructors in a mirror fashion. While a constructor creates an instance, a destructor removes an instance. Destructors And Resource Release Many languages have a default destructor, much as they have a default constructor. These methods likely free up some pointers behind the scenes. However, we also have resources and properties or even notifications that may be needed as part of this process. That leads us to a process that effectively undoes the creation and initialization steps. We first release resources (reverse the initialization). Then we remove the instance from... Read more