Does the destructor deallocate memory assigned to the object which it belongs to or is it just called so that it can perform some last minute housekeeping before the object is deallocated by the compiler?
Does the destructor deallocate memory assigned to the object which it belongs to or
Share
The ‘compiler’ doesn’t delete anything. It creates code that does things at runtime.
When you write
delete somePointer;the compiler, in essence, writes:In other words, the destructor gets called, and then operator delete gets called to free the storage.
If the destructor is virtual, a virtual dispatch is used to perform the entire operation on the object in its most-derived form. A common way of implementing this is to add hidden arguments to every virtual destructor.
Note that the top-level if statement isn’t really part of the generated code; the compiler makes that decision at compile-time.