Dangling Pointers/ Memory Leak definitions...
Let me see if I have this (in my own words) correct?
A Dangling Pointer is when dynamic memory has been deallocated
(free/delete) but there is one or more Pointers still pointing to it.
A Memory Leak is when all the Pointers to dynamic memory have
been lost. So the memory can neither be accessed or deallocated.
So is the rule of thumb this: When the last pointer to dynamic memory
is about to be "lost", deallocate the memory using that pointer. When
memory is deallocated, make sure all pointers to it are NULLed.
Have I Left out anything? Any variations of the above?
A Dangling Pointer is when dynamic memory has been deallocated
(free/delete) but there is one or more Pointers still pointing to it.
A Memory Leak is when all the Pointers to dynamic memory have
been lost. So the memory can neither be accessed or deallocated.
So is the rule of thumb this: When the last pointer to dynamic memory
is about to be "lost", deallocate the memory using that pointer. When
memory is deallocated, make sure all pointers to it are NULLed.
Have I Left out anything? Any variations of the above?
sounds good.
you'll find that most of the time, most people won't NULL pointers to stuff they've just deallocated, usually either because that pointer is itself about to be deallocated, or because they're just about to assign a new value to it. It'll never hurt to do so though
you'll find that most of the time, most people won't NULL pointers to stuff they've just deallocated, usually either because that pointer is itself about to be deallocated, or because they're just about to assign a new value to it. It'll never hurt to do so though
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Combined declarations and definitions in .h file | WhatMeWorry | 15 | 5,200 |
Dec 1, 2006 10:34 AM Last Post: WhatMeWorry |
|
| Should global variables be pointers or full objects? | ia3n_g | 1 | 2,085 |
Aug 4, 2006 05:53 PM Last Post: OneSadCookie |
|
| reading void pointers | Duane | 16 | 6,244 |
May 10, 2005 03:47 PM Last Post: Puzzler183 |
|
| NULL versus 0 pointers? | WhatMeWorry | 14 | 6,594 |
Apr 6, 2005 05:42 AM Last Post: Andrew |
|
| Pointers & Archiving in Cocoa | Shivers | 6 | 3,499 |
Apr 4, 2005 02:36 AM Last Post: DoG |
|

