Re: [Gc] Marking memory as traceable

Ivan Maidanski ivmai at
Tue Apr 20 01:25:40 PDT 2010

Tue, 20 Apr 2010 09:34:20 +0200 Christian Gudrian <christian at>:

> Hello!
> I'm using the collector on Windows with Embarcadero RAD Studio 2010 and 
> VCL applications.  The VCL framework classes' memory is not traced by 
> the collector so whenever I put references to garbage collected memory 
> into such a class, I wrap the references in a struct which then gets 
> allocated by GC_malloc_uncollectable during construction and accordingly 
> freed during destruction.
> Since that's a bit too cumbersome for me I would like to tell the 
> collector to trace a certain portion of memory for referenced object.  
> Initially I thought that what's GC_add_roots for, on Windows, however, 
> its counterpart GC_remove_roots is obviously not implemented.  Hence I 
> would end up continually adding roots to the collector while being 
> unable to remove those which have become invalid.

In theory, it's possible to implement GC_remove_roots() for Win32.
But, it is complicated due to overlapping/adjacent regions processing.

In general, IMHO, GC_add_roots() is not intended to be used for malloc'ed objects (for efficiency reasons), so, I'd prefer your solution (in any case you need a destructor). Another way, is to define a class which wraps a single traceable reference using GC_malloc_uncollectable(ptr_size) (IMHO, it might be a good idea to have a public header file in the GC distribution defining such class like WeakPointer does).

> Should I stick to using my traceable struct or is there a better way?
> Christian

More information about the Gc mailing list