Soft, weak & phantom reference

Hi all :)
A short while ago, I began to study "java.lang.ref" package. It's not so easy to me. Also I've gotten many relative questions & answers from this forum, here is a problem confused me for so long time :( Please help me out, thanks!
import java.lang.ref.*;
import java.util.Hashtable;
public class TestMe {
    private Hashtable ht = new Hashtable();
    private ReferenceQueue rq = new ReferenceQueue();
    public TestMe() { }
    private void clearQueue() {
        SoftReference r;
        while ((r = (SoftReference)rq.poll()) != null) {
            Object obj = r.get();
            if (obj != null) {
                //* Here is the problem: why this always doesn't work?
                // using weak or phantom reference is same like soft reference here :(
                System.out.println("=> " + obj);
            ht.remove(r);
    public void put(Object key, Object obj) {
        clearQueue();
        ht.put(new SoftReference(key, rq), obj);
    public static void main(String[] args) {
        TestMe tm = new TestMe();
        int i=0;
        while(true) {
            tm.put(Integer.toString(i++), new String("wow"));

The reference object is put into the reference queue after all SoftReferences to the reference object have been cleared. Since you're trying to get the reference pointed to by the SoftReference after it's been queued, it is null.
If you want to store some information to use after the reference object has been queued, you need to subclass the SoftReference class and store the information in a field.

Similar Messages

  • IterateOverReachableObjects and soft/weak/phantom references

    Hi,
    what are soft/weak/phantom references for the JVM TI call IterateOverReachableObjects? Are those reference-objects
    1. ... "normal" objects having references and beeing traversed by this function
    (OR)
    2. ... interpreted as references with hiding the object nature
    (OR)
    3. ... ignored as they are ignored by the GC?
    Thanks,
    Robert

    The reference_kind with JVMTI_REFERENCE_FIELD, the referrer_tag will be the value of the tagged Reference instance, and the referrer_index will be the index of the "referent" field. It is this field that is treated in a special way by the GC.

  • How strong ,soft ,weak ,phantom references are used in garbage collection

    Hi
    to all here.I have doubt that how garbage collection is deciding to cleaning up heap , and what are the roles of strong , soft , weak and phantom reference in garbage collection, i went throgh sun's java docs but i couldn't get any clear idea about those , please can anyone explain me with nice examples for which i will be really thankful.

    See:
    http://java.sun.com/developer/technicalArticles/ALT/RefObj/

  • Weak, soft and Phantom references

    I have got some confusions about reference types in java. These are:-
    1. How we create weak and soft references! Are they predefined classes and we extend them, or they are interfaces and we implement them, or they are the concepts we implement by following any particular pattern.
    or the references which are gone out of scope are considered as weak references.
    2. can we change the type of reference dynamically! as JVM does it.
    for eg:-
    While the data objects are actually in use (or they are in scope) they are immune because they are strongly referenced by the display windows, once you move to look at something else (or they go out of scope) they become eligable for removal.
    3. There is one set of problem I am facing, could that be resolved by weak or soft references.
    "I set variables at session level(if they are needed at more than one page."
    "At the last page I remove it from session."
    "If for example there are 4 page sequence, and user quits after three steps, then the garbage variables are left in the session."
    "if I make them as weak reference(or soft reference) then would it be a solution. or will it increase any potential risk of loosing the variables in between the process."
    "or is there any way out for my problem using ref package, or it is used only for special purposes, not for a senario like this."
    "or I am bound to use request level instead of session level, in these type of problems(which I am presently doing to solve this problem, but in this case I have to to set same attribute 3 times.)"
    please comment.
    4. What happens when we create an instance of reference queue.
    -->does it give us a reference to the main queue that is used by garbage collector. when destroying objects out of scope.
    that is garbage collector removes the reference of from the object and makes it point to queue element.
    --> or when object goes out of scope, at that time only the reference is removed from the object and is made to point to queue element.
    --> and when we do obj=null; at that time also obj reference is made to point to queue element.
    please comment. I am confused about how java handles references.
    5. does reference queue takes all the junked references.
    if yes!
    then for eg. we are using a background thread and doing some work when instance of class A is cleared, and doing some other work when instance of class B is cleared up by garbage collector.
    queue.remove will return the junked reference, now how will we be determining which object is junked, instance of class A or class B. As reference of object is junked we can't use instanceOf operator.
    please comment.
    Thanks.

    I find the documentation a bit opaque myself.
    You create, say, a Weak reference by creating an object of class WeakReference, or a subclass of same. The object referenced (the referent) is a separate object which you pass in the WeakReference's constructor.
    As long as the referent exist then calling get on the WeakReference object will return it. Once you call get and put the resulting reference in an object you have a hard reference and you know that the referent won't disappear until you let go of it.
    If the referent has been disposed of then get returns null.
    Sometimes you want to do extra cleaning up when a reference is cleared. Then you need to subclass the Reference class you are using to add indentifying information about the object that just disappeared. Obviously this can't be a reference to the object itself, that would be a "Hard" reference and would prevent the object being cleared.
    You then create a ReferenceQueue, which is an ordinary object you own. The Reference objects have a reference to this queue. What happens is the the GC, when it clears one of these Reference objects, adds the Reference to the queue it references. You run a background thread which takes these cleared references from the queue and, using the extra information you added when you subclassed them, does whatever cleaning up you need to do. A typical example is that you have a Map, with the Reference objects as values. Each reference is extended to store the key, so that the cleanup will remove cleared references from the map.
    No, it's not suitable for session objects, because you can't depend on the object still being arround. You can only rely on session timeout. It's a basic problem with web services that you never really know if the user has gone away and abandoned you.

  • Soft/Weak References: rule of thumbs?

    After reading <a target="extern" href="http://java.sun.com/developer/technicalArticles/ALT/RefObj/index.html">Reference Objects and Garbage Collection</a> i browsed my code and replaced my listener containers with versions that store WeakReference objects. The main idea is to avoid memory leaks by storing references to objects that are not needed anymore (the listener container is the only strong reference left).
    Another rule is to use SoftReferences for caches. But I haven't figured out a good way of implementing it (for caches that fill itself with one single SQL statement).
    Are there any other examples where it's good advice to use Soft/Weak References?

    For listeners, you have to make sure that the listener object is hard referenced - which is usually the case. After you release the listener object from the main application/object/thread, because it's finished or you don't need it anymore, the listener holder should not hold on to such references to avoid OutOfMemoryExceptions. Of course, the best way is always to unregister a listener, but unfortunately, we're not living in a perfect world. No listener is forced to unregister, they can simple forget to unregister. For this reason, it's better to tell the listener: if you register yourself, you should know that you are just referenced via WeakReferences. If the listener suddenly doesn't get listener events, this is a coding error which can be traced and fixed. But if a listener forgets to unregister itself, the resulting memory bloat is much harder to trace.
    SQL table caches are difficult. On one hand you want to cache the data, on the other, you want to free this cache memory (temporarily) for more important memory usage. It's always a trade off between 2 advantages. If performance is not the big issue, but you get OutOfMemoryExceptions, then this is critical for the application to continue working. Better a little slower than not at all ... ;-)

  • Please explain soft/weak references to me!

    What I would like to do is have following class:
    abstract class ImageContainer
      private Image img;
      public Image getImage()
        if (img==null)
          renderImage();
        return img;   
      public void lowMemory()
         img=null;
         System.gc();
      abstract protected void renderImage();
    }I think that you get my point, but this doesn't really work, since there's noplace where from call lowMemory() (and I mean low RAM memory, not low swapping memory, since this is to remove swapping during gameplay). I need somehow to use soft references or something like that so I was wondering if you could point me to right direction... I was unable to understand completily the API for package java.lang.ref

    abstract class ImageContainer
    private SoftReference imgRef = new SoftReference();
    public Image getImage()
       Image img = (Image)imgRef.get();
       if (img==null)
          img = renderImage();
          imgRef = new SoftReference(img);
       return img;
    abstract protected Image renderImage();
    }Reference objects "wrap" a regular hard reference, passed into the constructor. The "get" method returns that reference, or null if the object has been collected. (After a GC cycle for WeakReference, after a low-memory condition for SoftReference.) Therefore, upon fetch, call "get" on the reference class and check for null. If null, recreate and create a new reference class instance. Return the object either re-fetched or just created.

  • Memdbg,  Weak handles proccessed and Hard handles processed means what?

    I have verbose gc logging running with memdbg on. I see lines in my logs that say:
    Hard handles: Processed 40789 handles during normal processing.     
    Weak handles: Processed 19954 handles during normal processing.     
    Weak handles: Processed 19868 handles during normal processing.     
    The number of handles keeps growing and all the documention I can find says about what this means is:
    "Lines 7 and 8 show information on weak and hard handles. This is mostly useful for advanced diagnostics and monitoring. "
    Is this how many handles left after GC or how many cleaned? Can anyone point me in the right direction?
    Thank you,
    Pat

    Hi,
    Your app specs are outside of what we recommend. But even with that taken into account, it does look a bit strange. Example:
    [gcpause][Tue Sep 18 19:50:32 2007][21873] old collection phase 4-5 pause time: 17653.675067 ms, (start time: 31020.348 s)
    [gcpause][Tue Sep 18 19:50:32 2007][21873] (pause includes wb processing: 17653.193 ms, compaction: 0.252 ms (external), update ref: 0.002 ms)
    17s time and most of it spent in "wb processing". One of the things happening here is processing of reference objects (soft, weak, phantom, finalizers). WLRT can currently not handle more than a few thousand such objects with good performance.
    A JRA recording would provide more info. See here:
    http://e-docs.bea.com/jrockit/tools/jmcpdfs/mc3/mcjra3.pdf
    Let us know how it goes. BEA does have specialists who can help you move forward as you evaluate WLRT; and we can loop one in here if needed.
    -- Henrik

  • Java.lang.ref  ???? help

    under what conditions,we use the java.lang.ref ??
    what's the useness of SoftReference , WeakReference,and PhantomReference ?
    please give me a clear ,concise,and constructive explanation
    i appreciate it !

    under what conditions,we use the java.lang.ref ??
    what's the useness of SoftReference ,
    WeakReference,and PhantomReference ?
    please give me a clear ,concise,and constructive
    explanation
    i appreciate it !Try looking at these links:
    On Reflection:
    http://java.sun.com/docs/books/tutorial/reflect/index.html
    http://developer.java.sun.com/developer/technicalArticles/ALT/Reflection/
    http://java.sun.com/products/jdk/1.1/docs/guide/reflection/faq/faq.html
    On Reference Objects and the garbage collector:
    http://developer.java.sun.com/developer/technicalArticles/ALT/RefObj/
    Javadocs on Weak, Soft, and Phantom Reference:
    http://java.sun.com/j2se/1.3/docs/api/java/lang/ref/PhantomReference.html
    http://java.sun.com/j2se/1.3/docs/api/java/lang/ref/SoftReference.html
    http://java.sun.com/j2se/1.3/docs/api/java/lang/ref/WeakReference.html

  • Soft references

    1) The only difference that I know between soft references and weak references is that weak references are guaranteed to be garbage collected, however soft references would be garbage collected only if JVM is running out of memory. Now my question is would the JVM rather resort to using virtual memory in case required than garbage collecting soft references or would it garbage collect befor that.
    2) Phantom references are objects on which finalize method has been run. So finalize method does not run on phantom references. Now when would you in real life use class java.lang.ref.PhantomReference for large objects which you dont want to take the risk of being resurrected. But as per my information if youo don't override the finalize method, there is no chance of resurrection. Can anybody point out any real life examples when it might be useful to use phantom references.

    1) The only difference that I know between soft
    references and weak references is that weak
    references are guaranteed to be garbage collected,
    however soft references would be garbage collected
    only if JVM is running out of memory.Untrue and not in agreement with the Javadoc. There
    is no guarantee that any object or reference
    is guaranteed to be garbage-collected, including weak
    references. Soft references are stronger than weak
    references and AFAIK they are GC'd before them if GC
    ever happens.Can you post any links which proves its not true. As per
    http://java.sun.com/developer/technicalArticles/ALT/RefObj/
    Weakly Reachable
    An object is weakly reachable when the garbage collector finds no strong or soft references, but at least one path to the object with a weak reference. Weakly reachable objects are finalized some time after their weak references have been cleared. The only real difference between a soft reference and a weak reference is that the garbage collector uses algorithms to decide whether or not to reclaim a softly reachable object, but always reclaims a weakly reachable object.
    >
    Now my question is would the JVM rather resort tousing
    virtual memory in case required than garbage
    collecting soft references or would it garbage
    collect befor that.This question doesn't make sense. The JVM always uses
    virtual memory, because the operating system does.
    The JVM will GC when it feels it needs to. There
    isn't a strong relationship between these things.Yes JVM will GC whenever it feels like but the whole idea behind having the reference classes was to The main feature of the reference classes is the ability to refer to an object that can still be reclaimed by the garbage collector for better memory mgmt.
    >
    2) Phantom references are objects on which finalize
    method has been run.Nope. Phantom references are references, not objects.
    ' An object is phantom reachable if it is neither
    strongly, softly, nor weakly reachable, it has been
    finalized, and some phantom reference refers to it.'
    yeah i should have been careful with my wording. An object is phantomly reachable when the garbage collector finds no strong, soft, or weak references, but at least one path to the object with a phantom reference. Phantomly reachable objects are objects that have been finalized, but not reclaimed.
    So finalize method does not run
    on phantom references.Make up your mind. You just said they have already
    been finalized. Both statements are wrong.I was talking about instantiantions of java.lang.ref.PhantomReference that finalize method won't run on these objects.
    >
    Can anybody point out any real life examples whenit
    might be useful to use phantom references.You would use phantom references plus a queue
    instead of finalize() methods, e.g. where you
    can't add finalize() methods to the classes but you
    still want to know when the instances have
    disappeared.finally I did find some reasonable explanation to these references
    Phantom references
    A phantom reference is quite different than either SoftReference or WeakReference. Its grip on its object is so tenuous that you can't even retrieve the object -- its get() method always returns null. The only use for such a reference is keeping track of when it gets enqueued into a ReferenceQueue, as at that point you know the object to which it pointed is dead. How is that different from WeakReference, though?
    The difference is in exactly when the enqueuing happens. WeakReferences are enqueued as soon as the object to which they point becomes weakly reachable. This is before finalization or garbage collection has actually happened; in theory the object could even be "resurrected" by an unorthodox finalize() method, but the WeakReference would remain dead. PhantomReferences are enqueued only when the object is physically removed from memory, and the get() method always returns null specifically to prevent you from being able to "resurrect" an almost-dead object.
    What good are PhantomReferences? I'm only aware of two serious cases for them: first, they allow you to determine exactly when an object was removed from memory. They are in fact the only way to determine that. This isn't generally that useful, but might come in handy in certain very specific circumstances like manipulating large images: if you know for sure that an image should be garbage collected, you can wait until it actually is before attempting to load the next image, and therefore make the dreaded OutOfMemoryError less likely.
    Second, PhantomReferences avoid a fundamental problem with finalization: finalize() methods can "resurrect" objects by creating new strong references to them. So what, you say? Well, the problem is that an object which overrides finalize() must now be determined to be garbage in at least two separate garbage collection cycles in order to be collected. When the first cycle determines that it is garbage, it becomes eligible for finalization. Because of the (slim, but unfortunately real) possibility that the object was "resurrected" during finalization, the garbage collector has to run again before the object can actually be removed. And because finalization might not have happened in a timely fashion, an arbitrary number of garbage collection cycles might have happened while the object was waiting for finalization. This can mean serious delays in actually cleaning up garbage objects, and is why you can get OutOfMemoryErrors even when most of the heap is garbage.
    With PhantomReference, this situation is impossible -- when a PhantomReference is enqueued, there is absolutely no way to get a pointer to the now-dead object (which is good, because it isn't in memory any longer). Because PhantomReference cannot be used to resurrect an object, the object can be instantly cleaned up during the first garbage collection cycle in which it is found to be phantomly reachable. You can then dispose whatever resources you need to at your convenience.
    Arguably, the finalize() method should never have been provided in the first place. PhantomReferences are definitely safer and more efficient to use, and eliminating finalize() would have made parts of the VM considerably simpler. But, they're also more work to implement, so I confess to still using finalize() most of the time. The good news is that at least you have a choice.
    http://weblogs.java.net/blog/enicholas/archive/2006/05/understanding_w.html

  • Weak references

    Why is it that SoftReference overrides the get() method in the Reference class. I can undertand that phantom references must do this as they always return null from get() but why is it so with soft refs?
    Andrew

    It updates a Timestamp field each time the get method is invoked. The VM may use that field when selecting soft references to be cleared (but it isn't required to do so)

  • Toplink Cache "back reference" best practice question.

    I have too many objects being stored in the Identity map. I'm using the default Soft/Weak map. The problem is every objects connects to every other objects. Since every objects can somehow be traced to each other all objects nothing is removed.
    Let's look at an example. I have two objects Projects and Tasks. A project has a collection of tasks and the task's have a "back reference" to the project. If just one task is in the "soft" section of the Identity map then all the other tasks, which are in the weak section, aren't eligible for garbage collection. The task has a simple OneToOne mapping to the project. I'm using a valueholder to hold the project. This particular instance doesn't use indirection, but there are many other objects that have a similar setup that do.
    These mappings are really convenient for reporting. For example through any task I can easily print the project's name. No query, joining, etc is necessary. This is critical to the app because we have a dynamic report builder where end users and print off anything they want. This flexibility though all of our mappings enables us to build a powerful report builder. Besides the report builder there are other modules that work in a similar fashion. Needless to say the application will build with the assumption that these "back references" exist. That said, I need to remove objects from the identity map.
    Is there a way to manually remove / invalidate the back references and have it repopulated on access? Similar to how indirection works?
    Is it possible to re-init an indirection value holder?
    Does anyone have any suggestions?
    I've looked at using an invalidation policy but that doesn't seem to remove anything. It still keeps the objects in memory. It just refreshes the object on access.

    Soft references should still garbage collect when memory is low, so you should still be ok memory wise, even with your cycles. If you want memory to be freed more aggressively, then use a Weak cache instead of Soft, or decrease your Soft cache size.
    There is no refresh() or revert() API on a ValueHolder, but if you refresh the source object, it will revert all of its relationships. Having a refresh() or revert() API of ValueHolder would be useful, so feel free to log an enhancement request on EclipseLink for that. You also may be able to cook something up using the mapping and readFromRowIntoObject(). Another option would be to just set the relationship to null and invalidate the object so it is refreshed when next accessed.
    James : http://www.eclipselink.org

  • Help required with understanding References and finalizers

    Background
    I have an online Application which has been developed over 6 years now. It is a Website CMS and runs 300 simultaneous sites per webserver. For the first time I am experiencing capacity / performance issues. I switched from SUN Java to JROCKIT in 2006 which speeded evertything up by 200% but now I have periods of the day where The memory fills up and I get Swapping which leads to 100% cpu utilization - mainly in I/O. I have upped the RAM in the server as a solution and now I want to see if I can do anything to reduce my memory footprint.
    Specifically : The question
    I have captured stats which I can view in Mission Control and it shows that the number of Weak References increases continuously over a 4 hour period (also the number of Phantom references shows similar behaviour). Therefore I suspect a memory leak - Also I suspect that this is of my own making since I have not realy had to deal with this before. The thing is I cannot clearly see how to proceed and identify what my error is.
    I have spent a couple of weeks reading loads of docs about weak / stong etc.. references but I realy need a bit of help with zeroing in on a starting point. I know that I release objects by setting them to null but I now expect that this is not realy good enough.
    Anyway - before I ramble too long, If there is anyone with relevant experience and a few minutes I would be very gratefull to hear from them.
    Regards
    Jonathan Carter
    Glimworm IT
    Amsterdam

    Hi Jonathan,
    Reference objects and finalizers are a frequent cause of performance issues. The reason is that 1) objects tend to be kept alive longer, leading to an increase in live data and more frequent GC and 2) processing of these objects during GC is expensive, which leads to more time spent in GC, i.e. long pause times.
    There are various ways you can approach your issue. One is to use -Xverbose to see what you find. If you are using JRockit R27.2 or later, run with "-Xverbose:referents" to get a list of all reference objects at every GC. More info:
    http://edocs.bea.com/jrockit/jrdocs/refman/optionX.html#wp1029960
    Note that you can enable verbose logging during runtime through "jrcmd <pid> verbosity set=referents" and later disable it using "jrcmd <pid> verbosity set=referents=warn". No JVM restart required.
    If you send your JRA recordings to jrockit-improve AT bea DOT com, we'll try to take a look at them.
    -- Henrik

  • How do I create a runtime library reference from a J2EE library DC?

    I've created a J2EE library DC that references some classes in an already deployed library.  The referenced jar file has been correctly deployed, as it's successfully used by some other components.  I can build the DC, since I've created created a compile-time reference to the local copy of the target jar file.
    Unfortunately, I can't figure out how to create a runtime reference from my J2EE library to the already deployed library - there just doesn't appear to be any place to put the reference, at least using a gui-based function in NWDS.  Unlike WebDynpro, which has a 'references' configuration option, J2EE lib's don't appear to have anything similar.
    Where/How can I do this?
    BTW, the Visual Administrator function 'ClassLoader Viewer ' is a very handy tool for diagnosing ClassDefNotFoundError errors....

    Hello Ken,
    well it seems to be not a trivial thing.
    1) Build your library DC.
    2) Create folder "server" in root DC folder "_comp".
    3) Extract provider.xml from generated SDA file to "server" folder.
    4) Add references in provider.xml:
        <references>
          <reference type="library" strength="weak">
            sapxmltoolkit
          </reference>
          <reference type="library" strength="weak">
            com.sap.lcr.api.cimclient
          </reference>
          <reference type="service" strength="weak">
            tc~sec~securestorage~service
          </reference>
        </references>
    5) Rebuild DC. Deploy.
    6) Enjoy!
    Useful links:
    http://help.sap.com/saphelp_webas630/helpdata/en/b5/22123b8d92294fac207283f3e8756e/content.htm
    http://help.sap.com/saphelp_webas630/helpdata/en/09/5d963be736904c96cbdfe93793eb42/TEMPLATE_image002.gif
    Best regards, Maksim Rashchynski

  • T6060 possible problem/error of production...Central speaker is weaker and faded than the others

    I just noticed on my recently bought t6060 that the center speaker sounds weaker and faded compared to the other satellites. what might be the problem? i know that the center speaker is intended for voice reproduction in 5.1 streams. On dvd playback i hear the voices, but not as clearly as other sounds that are reproduced by the satellites. When testing the speakers, when naming each channel, the center speaker is softer, faded and weaker than the others. Is it normal to be this way or do I have to return the product to service? Please tell me what to do...if there is anymore testing to be done, or if this is the normal way it should sound.
    I tried to connect one of the other 8 watt satellites to the center connector, and it sounds perfectly clear, so there should be good audio output on the center channel, but when i connected the central speaker, which is 8 watts of power in the place of the speaker that i had unplugged earlier before, the central speaker sounded as soft, weak and fade as before. What is the problem? Do I have a defective central speaker? Please guide me what to do. I am kinda disapointed by all this. I have a Creative Live! 7.1 24 bit which works fine and also a Creative MuVo V200 512 MB, and i am very pleased with both of them. That's why I chose Creative for my 5.1 speaker system. Help, please. Thank you very much for your earliest attention.

    there was a real faulty center speaker, they've aknowledged the problem and they changed the whole system with a brand new one, which works pretty good. SOme things i have noticed comparing the two packages. I am afraid that the first set that i got was some sort of an RMA product that had been fixed, because although the seals were intact, and the inner boxes seemed new, but the small plastic bags that contained the speakers were somehow damaged and the speakers were not that well packed as this new set that i got a few days ago. The thing that i noticed, unfortunately is that i have now the same problem as SMSMASTERS reported, the fluctuation of the volume. It is perceptible, but after a little bit of fine listening. It's definitely there... I frankly am dissapointed in Creative for not being able to make a good solid product. And how could they market a product that, as you can see on this forum, has so many problems and bugs that need to be fixed? I would advise all those who want to buy new products and recently marketed products from creative to wait a little bit more and not haste into it...i think the best speaker set that will be marketed under the name of t6060 would be somewhere in spring or summer of this year, probably the revision B or C series, cause this one really sucks. The speakers are alright, and they sound pretty clear and accurate, and it's probably a problem with the remote, as other people reported on the forum, but it's simply rude and disconsiderate to buyers and especially to Creative fans to release a product with so many bugs that need to be fixed. It's a shame really, and a huge dissapointment. I wonder how you all feel, all of you who posted on this forum about bugs related to your hardware...

  • References question

    I wanted to create references that did some cleaning up by themselves when they were discarded because of low memory, so I tried to extend the clear method, but it seems that it is never called.
    I thought, reading API and docs I found, that the GC calls the clear() method of a SoftReference when it moves the reference to the queue. But it appears that the GC does not use this method, but in stead clears the referent in some other way. Can someone confirm this, and maybe explain why?
    I suppose I will need to use a referencequeue and poll every now and then ...

    I thought, reading API and docs I found, that the GC
    calls the clear() method of a SoftReference when it
    moves the reference to the queue. But it appears that
    the GC does not use this method, but in stead clears
    the referent in some other way. Can someone confirm
    this, and maybe explain why?That makes sense, although I cannot confirm for sure. My reasoning follows...
    It is my understanding that the GC is guaranteed to clear and collect all SoftReference referents before throwing an OutOfMemoryError. If the GC clears the referents by calling an extensible method - in this case, clear() - it can no longer make this guarantee... simply because it cannot guarantee that your custom clear method will not require the allocation of memory that isn't available.
    I am not overly knowledgeable about References, but I believe that PhantomReference is the only kind that prevents the object from being collected before the reference is cleared... this should allow you to perform your cleanup. If anyone has an example of this, I would be obliged to see it, because I have been unable to think up an example that would work...
    Since you cannot get a reference to your object through a phantom reference, you can tell when an object is eligible for collection, but not which object or what resources it holds that might need to be released. It may be possible to create the reference as an inner class of the object requiring cleanup, but this technique would require a dedicated thread for every object requiring cleanup, doing nothing but waiting for the reference to be enqueued. This is as unscalable as any other thread-per-object model.
    It may be apparent that I have talked myself in circles in this matter a few times now... if anyone holds the Ariadne's thread to this issue, I would love to see a phantom reference in a useful context.
    Apologies if I confused the issue more than I clarified it.

Maybe you are looking for

  • OS X Server 10.4.11 freezes when misc files are being accessed

    This is an odd problem, to me at least. It seems as if I have some files that are getting corrupted, that then cause my 10.4.11 server to lock up when they're accessed. Has anyone else run into this problem before? This server is really only used for

  • I have a new computer, how do i sync my apps from my iphone and ipad

    my mac book pro crashed and I have a new hard drive....I don't have access to the old one.  My iphone and ipad are synced with icloud, but how do i sync with the new computer without loosing my apps? 

  • Clear device list on a EA2700

    I have a cisco EA2700. Does anyone know how to clear the connected devices list? I want to use the parental controls, but when I look at the list it shows every device that was ever connected to my wireless. PLEASE how can I flush the list Thank You

  • SWF header duration reduced to 2 frames after using a Motion Preset

    It seems that after you apply a Motion Preset the header of an exported SWF reports an incorrect duration of 2 frames even though its much longer. Also, after removing the elements that are related to the Motion Preset, the SWF still reports 2 frames

  • Unable to Extract from Oracle

    Dear Team, I am very newer in Golden Gate. Going thru with the blog and trying to learn. http://www.pythian.com/news/7959/oracle-goldengate-installation-part-1/ I was trying to extract from the Oracle tables at the time of extraction it’s giving erro