Sean Kelly wrote:
== Quote from Sergey Gromov (snake.sc...@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);

Wouldn't this code break it?

synchronized(mWeakPtr) {}

The GC would collect the monitor in the next GC run, and you had a dangling pointer. But then I don't really know enough about how objects are GC-scanned and how monitors are memory managed.

Reply via email to