[Gc] Pointer References to GC heap

Hans Oesterholt Dijkema hans at strader.xs4all.nl
Thu Sep 23 14:46:55 PDT 2004

> > 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 

> 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.

Hans Oesterholt-Dijkema

More information about the Gc mailing list