+ 5
What are destructors
any relation with constructors
5 RĂ©ponses
+ 9
Constructors are called when an object is created. Destructors are called when an object is deleted.
+ 18
They're comparable to constructors. While constructors instantiate objects, destructors delete them to free memory.
In both cases, you can add code to perform extra actions before instantiation/deletion. Ex: Closing files and databases, writing to a log file, etc.
An object is deleted when it leaves its scope. Ex: If you make an object in a method, that object is deleted after the method ends.
+ 8
Destructors are nothing but what destroys the scope of an object once it is no longer needed.
0
destructors are 360 opposite to constructor their task is to destroy the memory of object after use
0
constructor = created
destructor = deleted