> Thanks for your answer, but you're only confusing me more. Now which of
> both suggestions should I take?
I'd definitely avoid inheriting from SoftReference -- that just adds work for
the system. So base it on Weak or Phantom refs. Don't bother with my other
elaborations unless you have good reason to suppose they'd help (i.e something
more concrete than just me wondering aloud /whether/ they'd help).
> And it's still not clear to me why
> these are correct, a hint on what to read about references is enough.
It's just that by adding another field to the WeakReference which /also/ points
to the object in question, we have added a strong (i.e. normal) reference
between those objects. That is additional to the weak reference which the GC
will manage. Since we never let go of the HardReference object (until we don't
want it any more) it will stay strongly reachable. But then, since it has a
strong reference to the target object that will /also/ stay strongly reachable.
Thus that object will never be GCed while the HardReference itself is still in
use.
Perhaps you are being confused by the names. A WeakReference (or Soft or
Phantom) is only weak in it's "referent" (the object referece passed to the
constructor), all other fields are ordinary Java (i.e. strong) references.
-- chris
Hendrik Maryns - 13 Jun 2006 10:33 GMT
Chris Uppal schreef:
>> Thanks for your answer, but you're only confusing me more. Now which of
>> both suggestions should I take?
[quoted text clipped - 19 lines]
> Phantom) is only weak in it's "referent" (the object referece passed to the
> constructor), all other fields are ordinary Java (i.e. strong) references.
Ok, many thanks. I sort of guessed this was the explanation, but felt
too unsure. You reassured me :-)
In the meantime, I found a better solution which doesn’t use the hard
reference at all, but hey, I have it in memory now...
Thanks again, H.
- --
Hendrik Maryns
==================
http://aouw.org
Ask smart questions, get good answers:
http://www.catb.org/~esr/faqs/smart-questions.html