Robin Garner wrote:


I don't understand. How can weak references help short-lived objects reclaim?

Really what I'm saying is that this is the closest thing we have to a
hint to GC that objects can be collected soon - but it is not anything
like a proper free() call. There is no immediate reclaim of memory,
just the possibility that it will be reclaimed soon - and the object
may be garbage collected before you are finished with it!

Regards,
Oliver


Actually, it's kind of the other way around isn't it ? Nulling the last pointer to an object tells the GC that it can collect it (explicitly in the case of reference counting), whereas having a Weak Reference to an object says 'please tell me when on-one else wants this object', which results in the object staying around even longer.

Isn't this only the case if you register the WeakReference with a ReferenceQueue? If you do not do that, then the GC can collect the referent when it wants, and you will
just get a null back from a get() call on any WeakReference object.
So I imagine that keeping the object weakly reachable and not registering it with a ReferenceQueue says to the GC "you are free to collect this referent object at the
next collection if you wish".

Regards,
Oliver


cheers,
Robin

---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



--
Oliver Deakin
IBM United Kingdom Limited


---------------------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to