[Gc] Pointer References to GC heap

Sean Middleditch elanthis at awesomeplay.com
Thu Sep 23 20:12:11 PDT 2004


On Thu, 2004-09-23 at 23:46 +0200, Hans Oesterholt Dijkema wrote:
> > > behaviour). Or must I leave out the GC_free function, so
> > 
> > No, it will not, because you've already freed the memory.  GC_free
> > instantly frees memory the exact same as a call to free() does.  t is
> > now referencing an invalid address, same as it would have before.
> 
> Thank you; but what would then be a good strategy to follow
> (with GTK). It's maybe best to not free memory and leave it to
> the GC; this would prevent this situation from occuring, or should
> I best copy the char * pointer from gtk_entry_get_text() with 
> "GC_strdup"? 

I'm not sure I'm seeing the problem.  It's not bad if you free memory
you don't need anymore.

> 
> > You will end up with a possible problem on subsequent allocations,
> > though - the GC will allocate some future block in the same area, and
> > then the GC will see that t points into it - possibly causing it to 
> > be erroneously kept in memory longer than it should be.  Whenever 
> > you free a pointer, *always* set it to NULL.  (That is expected 
> > practice even when not using a GC.)  When you are done with a 
> > pointer, always set it to NULL.  (And free the memory if you think 
> > that is appropriate at the time.)
> 
> Thanks for the advice; however, I do not know many programs
> that actually take this oppertunity.

Most aren't written for a GC, either.  ;-)

> 
> > 
> --
> Hans Oesterholt-Dijkema
> 
> 



More information about the Gc mailing list