PDA

View Full Version : What is the difference between a leak and a dangling pointer?



Josh-TotalView-Tech
07-20-2006, 08:53 AM
If you have trouble remembering the difference between a leak and a dangling pointer, this may help. Before either problems occurs, memory is created on the heap and the address of this memory block is assigned to a pointer. A leak occurs when the pointer gets deleted, leaving a block with no reference. In contrast, a dangling pointer occurs when the memory block is deallocated, leaving a pointer that points to deallocated memory. Both are shown in the following figure.

http://www.etnus.com/Documentation/latest/html/TotalView_Tips/images/dangling.jpg