Keeping a list of instances and garbage-collection

Sean Kelly sean at invisibleduck.org
Mon Mar 30 17:02:20 PDT 2009


== Quote from Sergey Gromov (snake.scaly at gmail.com)'s article
> Sun, 29 Mar 2009 17:42:48 -0400, Chad J wrote:
> >
> > Maybe what you are looking for are the GC.removeRoot or GC.removeRange
> > functions which are available in both Phobos and Tango?
> > http://www.dsource.org/projects/tango/docs/current/tango.core.Memory.html
> > http://www.digitalmars.com/d/2.0/phobos/std_gc.html
> > http://www.digitalmars.com/d/1.0/phobos/std_gc.html
> You can remove only something previously added.  Since a static array is
> not a root nor a range of roots, you can't make it invisible to GC this
> way.

What you could do is turn off the HAS_POINTERS flag for the WeakPtr
object, assuming it's set to begin with (if your class just contains a size_t
for the pointer then it might not be).  This should avoid the need for
any weird tricks to obscure the pointer data.  On D2 you do this via:

GC.setAttr(myWeakPtr, GC.BlkAttr.NO_SCAN);



More information about the Digitalmars-d mailing list