Dangling Pointers/ Memory Leak definitions...

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
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,495 Dec 1, 2006 10:34 AM
Last Post: WhatMeWorry
  Should global variables be pointers or full objects? ia3n_g 1 2,313 Aug 4, 2006 05:53 PM
Last Post: OneSadCookie
  reading void pointers Duane 16 6,681 May 10, 2005 03:47 PM
Last Post: Puzzler183
  NULL versus 0 pointers? WhatMeWorry 14 6,997 Apr 6, 2005 05:42 AM
Last Post: Andrew
  Pointers & Archiving in Cocoa Shivers 6 3,718 Apr 4, 2005 02:36 AM
Last Post: DoG