Dangling Pointers/ Memory Leak definitions...

Member
Posts: 321
Joined: 2004.10
Post: #1
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?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
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 Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Combined declarations and definitions in .h file WhatMeWorry 15 5,743 Dec 1, 2006 10:34 AM
Last Post: WhatMeWorry
  Thread-Safe reference counted smart pointers in c++ JeroMiya 1 3,363 Nov 21, 2006 12:28 PM
Last Post: OneSadCookie
  Should global variables be pointers or full objects? ia3n_g 1 2,501 Aug 4, 2006 05:53 PM
Last Post: OneSadCookie
  reading void pointers Duane 16 7,000 May 10, 2005 03:47 PM
Last Post: Puzzler183
  NULL versus 0 pointers? WhatMeWorry 14 7,350 Apr 6, 2005 05:42 AM
Last Post: Andrew