We know that it is needed to specify the destructor of a base class as virtual if you intend to use it polymorphically, otherwise you might have a ressource leak in your program, since only the base class destructor will be called and not the derived object destructor.
We also know that constructors / destructors are purely initialization / uninitialization constructs, and operator new / operator delete handle the allocation / unallocation of memory.
In that case, why exactly does the lack of destructor-calling incur a leak, in the case where my C++ class contains only primitive data members? Would it be more accurate to say that the operator delete cannot unallocate the memory, and that is what creates a resource leak?
Aucun commentaire:
Enregistrer un commentaire