Doing due diligence of VC-baked software startups, I get to see a lot of code like this:
SalesOrder * Order = new[100]; …
delete Order;
The developer has just created a memory leak. The destructor ~SalesOrder() will only delete the first order, orphaning the remaining 99 on the heap. The correct call to release all the memory of the 100 orders is as follows:
delete [] Order;
You can confirm this by simply inserting a cout statement in the destructor.
Chad Salinas
Filed under: Uncategorized | Tagged: C++, memory leak