[concurrency-interest] Atomicity of clearing of WeakReferences

Bob Lee crazybob at crazybob.org
Tue Jul 14 19:46:35 EDT 2009


On Tue, Jul 14, 2009 at 4:28 PM, Joseph Seigh <jseigh_cp00 at xemaps.com>wrote:

> If you have more than one WeakReference pointing to an object, and the
> object no longer has any normal references, are the references cleared
> atomically?   Or can you bring an object back into play by getting a
> reference to it from a WeakReference that hasn't been cleared after seeing a
> different WeakReference to it get cleared?
>

The spec says they are cleared atomically:

"Suppose that the garbage collector determines at a certain point in time
that an object is weakly
reachable<http://java.sun.com/javase/6/docs/api/java/lang/ref/package-summary.html#reachability>.
At that time it will *atomically* clear all weak references to that object
and all weak references to any other weakly-reachable objects from which
that object is reachable through a chain of strong and soft references. At
the same time it will declare all of the formerly weakly-reachable objects
to be finalizable." (
http://java.sun.com/javase/6/docs/api/java/lang/ref/WeakReference.html)

This would be easy to support in a stop-the-world collector, but it seems to
me that it could overly restrict concurrent collectors. Thoughts?

Bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20090714/72600c93/attachment.html>


More information about the Concurrency-interest mailing list