Skip to Main Content
Software Essentials
book

Software Essentials

by Adair Dingle
July 2014
Intermediate to advanced content levelIntermediate to advanced
436 pages
12h 27m
English
Chapman and Hall/CRC
Content preview from Software Essentials
216 Software Essentials
Why? e Derived class destructor was not invoked so the deallocation
code in the Derived destructor did not run.
Consider Example 7.21. Test this code yourself. When delete is called
on the base class pointer b, the call to the destructor is statically bound so
only the Base class destructor res: the 500 integers allocated on the heap
for the Derived class object thus leak, through no fault of the application
programmer. Memory leaks arise because the Derived class allocates heap
memory but the Derived destructor was not invoked.
Example 7.21: C++ Memory Leak: Only Base Destructor Called
// class hierarchy: Base ok; Derived class allocates heap memory
class Base
{ …
public:
Base() { … } // #A
~Base() { … }
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Software Architect’s Handbook

Software Architect’s Handbook

Joseph Ingeno
Economics-Driven Software Architecture

Economics-Driven Software Architecture

Ivan Mistrik, Rami Bahsoon, Rick Kazman, Yuanyuan Zhang
Software Architect Bootcamp

Software Architect Bootcamp

Raphael Malveau, Ph.D. Thomas J. Mowbray

Publisher Resources

ISBN: 9781439841204