answersLogoWhite

0

Destructors are used to free memory and release resources.

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

Does c language really supports destructors?

it doesnt support destructors


When is a destructor called?

Destructors are called when an object is no longer used. In a language like C++, this is done explicitly by the programmer when the delete operator is used on the object.


What is the main purpose in using a destructor?

Destructors are called automatically whenever an object falls from scope. Even if you don't actually declare a destructor, one is implied. The primary purpose of a destructor is to give the programmer one final chance to clean up an object's memory allocations before the object is destroyed forever. If an object has allocated memory associated with it (via member pointer variables), then that memory must be released before the object is destroyed, otherwise a memory leak is inevitable. Destructors are also important in class inheritance. When a derived object falls from scope, its immediate base class destructors are called, followed by their base class destructors. This is effectively the reverse of an object's construction, which always begins with the least-derived base classes, working up to the most-derived class, which is the object itself. Just as a derived class cannot be instantiated until all its base classes are constructed, a base class object cannot be destroyed until all its derived class objects are destroyed. All the destructors in a class hierarchy must be declared virtual to ensure the correct most-derived destructor is called whenever a base class reference falls from scope.


What is the Difference between virtual methods and non virtual methods in c sharp?

A function is a method that returns a value other than void. Methods includes functions, subroutines, constructors, destructors, and properties.


What is the importance of cloves?

what is the importance of cloves