Lowest price ever! Learn Generative AI for 48% less!
Get my discount+ 4
If the "Destructors" are used only for deleting an object then why do they have a body?
6 Answers
+ 2
A destructor prepares a single instance (object) for its (complete) deletion. This will not delete all existing objects of this class, but all members of this specific instance.
+ 6
Imagine you own 3 drones, but you need only 2. So you want to sell one, find a buyer and get rid of it. But before deactivating it, you might want to get sure, that it's not still in the air or has pictures of your wife stored on its SD card, right? And exactly that's a destructors job - to prepare an object for it's deletion. Loose the connections to other objects, delete dependent data etc.
+ 5
I get it now, thank you.
+ 4
Oh, I see. So it deletes particular objects and not all of them.
+ 4
The memory assigned to that instance of class
+ 1
You're welcome