2 ms·
Your way of saying it isn't wrong, but I think I would say instead that C++ uses destructors both for memory management and management of other resources.
by AnimalMuppet 7y ago
Your way of saying it isn't wrong, but I think I would say instead that C++ uses destructors both for memory management and management of other resources.
- brianush1 7y agoIf we're being pedantic here, destructors don't manage memory at all, they only free resources. Memory is freed by the caller of the destructor, either automatically if the memory was allocated on the stack, or manually by the delete operator if the memory was allocated on the heap.
- Someone 7y agoMemory is a resource, too, and C++-style destructors do manage it, sometimes. Destructors do not free the memory of the object being destroyed, but they can free memory that its fields point to.