[concurrency-interest] Atomicity of clearing of WeakReferences

Dhanji R. Prasanna dhanji at gmail.com
Tue Jul 14 20:06:20 EDT 2009


On Wed, Jul 15, 2009 at 9:46 AM, Bob Lee <crazybob at crazybob.org> wrote:

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

Concurrent collectors also pause all application threads during marking.
They just have shorter pauses as there are more marks done and the sweeping
is concurrent.

So it should not affect atomic clearing?

Dhanji.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20090715/cf4caa74/attachment.html>


More information about the Concurrency-interest mailing list