Leak 2

 <  Free Open Study  >  

Leak #2

Nested object pointers that are not cleaned up properly. A less obvious pitfall exists when one object contains another object by reference instead of by value. In the example code shown here, a Meal object contains a Melon object by reference (i.e., a Meal contains a pointer to a Melon ). This Melon is dynamically allocated in the Meal 's constructor and therefore must be deallocated in its destructor. The confusion occurs when a developer thinks that the Melon 's destructor is called automatically by the Meal 's destructor. Automatic destructor calls will occur when one object contains another by value. In our example, this would translate to a Meal object that contains a Melon object (i.e., by value).

 <  Free Open Study  >  


Object-Oriented Design Heuristics
Object-Oriented Design Heuristics (paperback)
ISBN: 0321774965
EAN: 2147483647
Year: 1996
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net