Garbage Collection Question

Discussions

General J2EE: Garbage Collection Question

  1. Garbage Collection Question (7 messages)

    Hi ,
       Is there any way that an application can know when an object created in its context is garbage collected.

    I dont know if this is the right fourm to post this question.

    Thanks
    puru

    Threaded Messages (7)

  2. Garbage Collection Question[ Go to top ]

    You can use the finalize() method, which is (sometimes) invoked when the object is garbage collected. Unfortunately, this method is not guaranteed, so it not 100% accurate.
  3. Garbage Collection Question[ Go to top ]

    There is no guarantee that the Object eligible for Garbage collection will be Garbage collected. But finalize() method is guaranted to be invoked once on the object being Garbage collected.
  4. Re: Garbage Collection Question[ Go to top ]

    You can read about garbage collection at
  5. Re: Garbage Collection Question[ Go to top ]

    You can read about garbage collection at http://www.java4all.info/articles/corejava/garbage-collection-java.html
  6. Garbage Collection Question[ Go to top ]

    I think you can do this using PhantomReferences and ReferenceQueues, although it's not something I've done myself. I vaguely remember reading an article about it some time ago.
  7. fyi, Weak references, Soft references[ Go to top ]

    Weak references and soft references:

    A program may request to be notified of changes in an object's reachability by registering an appropriate reference object with a reference queue at the time the reference object is created. Some time after the garbage collector determines that the reachability of the referent has changed to the value corresponding to the type of the reference, it will add the reference to the associated queue.

    package: java.lang.ref

    http://java.sun.com/products/jdk/1.2/docs/api/java/lang/ref/package-summary.html
  8. fyi, Weak references, Soft references[ Go to top ]

    Thanks a lot for all your replies. They were helpful, I'll do some experimentation based on the suggestions, and keep the group posted.
    Thanks
    Puru