Re: SoftReference operation synchronization detail



/Oliver Wong/:

Note that the reference called "cache" won't
magically turn into null behind your back. It's only the referent within the
SoftReference which may become null (which is why get() sometimes returns
null). So depending on the design of the rest of your code, the check for
cache != null might be unnescessary.

I haven't used the Reference classes up to now and seems I haven't
quite understood the description
<http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ref/SoftReference.html>:

Suppose that the garbage collector determines at a certain point in
time that an object is softly reachable. At that time it may choose
to clear atomically all soft references to that object...

The "choose to clear all soft references" part now I understand as
clear the references to the objects those Reference objects hold,
right?

But my main concern was because of some test of mine (not clear enough
thought) while playing with those Reference classes - I've got 'null'
values for the Reference variables themselves, after I have initialized
them. And reading further into the description:

... At the same time or at some later time it will enqueue those
newly-cleared soft references...

I don't understand how are the references processed from those queues,
given the they have already been cleared, but I've speculated that
process might have cleared my Reference variables, somehow. It is quite
possible I haven't overseen something, too.

That sounds most logical, but again: a Reference variable is never
cleared automatically?

--
Stanimir

.



Relevant Pages

  • Re: Write-to-disk cache via WeakReferences?
    ... > GCs treat the reference in Reference objects specially. ... > greater than the freed memory in megabytes). ... it has been my experience that SoftReferences are ... I had a cache of soft references and my own thread that would call ...
    (comp.lang.java.programmer)
  • Re: Passing parameters between form classes - C#
    ... In the first form, where you create and show the lookup form, make sure it ... you can only have reference variables that live inside a method. ... > private void InitializeComponent() ...
    (microsoft.public.dotnet.languages.vc)
  • Re: SoftReference operation synchronization detail
    ... newly-cleared soft references... ... process might have cleared my Reference variables, somehow. ... When using ReferenceQueues, you typically subclass the Reference implementation and add fields to that so you know what disappeared. ...
    (comp.lang.java.programmer)
  • Re: Explanation of object equality.
    ... string equality operator only works on reference variables of Type ... This is a reference based comparison. ...
    (microsoft.public.dotnet.languages.csharp)