garbage collector

Discussion in 'Java' started by raghu, Dec 18, 2005.

  1. raghu

    raghu Guest

    Why there is no guarentee for System.gc() method will perform garbage
    collection for a particular time?
     
    raghu, Dec 18, 2005
    #1
    1. Advertising

  2. raghu

    zero Guest

    "raghu" <> wrote in news:1134927095.209719.312850
    @g44g2000cwa.googlegroups.com:

    > Why there is no guarentee for System.gc() method will perform garbage
    > collection for a particular time?
    >
    >


    So your teacher gave you a list of questions and expects you to think about
    them and come up with a good answer, correct? May I suggest you actually
    do think about them, instead of asking us. Perhaps if you at least show
    that you thought about it by posting your thoughts, the group would be more
    likely to point you in the right direction.

    --
    Beware the False Authority Syndrome
     
    zero, Dec 18, 2005
    #2
    1. Advertising

  3. raghu

    Chris Smith Guest

    raghu <> wrote:
    > Why there is no guarentee for System.gc() method will perform garbage
    > collection for a particular time?


    Because it may not be possible for garbage collection work to be done
    right now. The virtual machine, languagem, and API specifications leave
    open the possibility for a wide variety of garbage collection
    implementations, and so no assumption is made that garbage collection is
    possible at arbitrary times.

    The contract for System.gc() makes two discrete guarantees:

    1. "Calling the gc method suggests that the Java Virtual Machine expend
    effort toward recycling unused objects in order to make the memory they
    currently occupy available for quick reuse."

    2. "When control returns from the method call, the Java Virtual Machine
    has made a best effort to reclaim space from all discarded objects."

    It's distressingly common to see people quote #1 rather ferociously, and
    then ignore #2. So to reiterate, you are GUARANTEED that when the
    system returns from System.gc(), a best effort has been made to perform
    any garbage collection work that can be done. The two statements --
    "suggests" and "best effort" -- are reconciled in that it's possible
    that no garbage collection effort is possible at all, in which case a
    best effort is equivalent to no effort at all.

    How is that possible? Two ways, that I can think of:

    1. Perhaps there is never any deferred garbage collection work in this
    implementation of the JVM. For example, perhaps it's a variant on
    reference counting with magic to collect cycles deterministically.

    2. Perhaps situations aren't right... for example, maybe it's a
    distributed JVM, and there's a network link down that prevents it from
    scanning the stacks of threads that are running on a different host.

    The definition of "best effort" is left rather vague, as well. Since
    software is written in advance, you could argue (circularly, of course,
    and rather unconvincingly) that a software's best effort always consists
    of doing whatever its code tells it to do... and thus any JVM conforms
    to that requirement by definition. However, most people would recognize
    that as word games. In the end, it comes down to the intuition of the
    virtual machine implementor what corresponds to a "best effort" of the
    existing software, versus changing the software itself. I'd say that if
    a garbage collection can be performed using the exposed API of the
    garbage collection module (however that's defined), then the VM is
    required to do it by the API specification.

    In practice, all common used garbage collectors do run garbage
    collection in response to a call to System.gc(). Barring unusual
    circumstances, it would almost surely be a violation of the API contract
    not to do so.

    --
    www.designacourse.com
    The Easiest Way To Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Dec 18, 2005
    #3
  4. Chris Smith wrote:
    >
    > It's distressingly common to see people quote #1 rather ferociously, and
    > then ignore #2. So to reiterate, you are GUARANTEED that when the
    > system returns from System.gc(), a best effort has been made to perform
    > any garbage collection work that can be done. The two statements --


    Perhaps it's just people with long memories of when System.gc was fast.
    Then one version, programs that call it lots slowed to a crawl.

    Tom Hawtin
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
     
    Thomas Hawtin, Dec 18, 2005
    #4
  5. raghu

    Chris Smith Guest

    Thomas Hawtin <> wrote:
    > Perhaps it's just people with long memories of when System.gc was fast.
    > Then one version, programs that call it lots slowed to a crawl.


    I've been working in Java since the summer of 1997, and I don't recall
    its ever being particularly fast. Not that I write much code that calls
    it.

    --
    www.designacourse.com
    The Easiest Way To Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Dec 18, 2005
    #5
  6. raghu

    Roedy Green Guest

    On 18 Dec 2005 09:31:35 -0800, "raghu" <> wrote,
    quoted or indirectly quoted someone who said :

    >Why there is no guarentee for System.gc() method will perform garbage
    >collection for a particular time?


    To protect you from foolishness. There is no point in doing GC unless
    you would actually get substantial RAM back.. You as programmer
    can't know that.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Dec 19, 2005
    #6
  7. Chris Smith wrote:
    > Thomas Hawtin <> wrote:
    >
    > I've been working in Java since the summer of 1997, and I don't recall
    > its ever being particularly fast. Not that I write much code that calls
    > it.


    I have a memory of a thread posted hereabouts around the 1.2->1.3 era
    (possibly) revolving around, IIRC, an image process library. The code
    slowed down significantly when upgrading. IIRC, it turned out that
    System.gc used to pretty much be ignored if there had just been a
    significant collection. The code called System.gc often, so with the old
    version it ignored most of them. However, I can't find anything relevant
    on groups.google.com.

    Tom Hawtin
    --
    Unemployed English Java programmer
    http://jroller.com/page/tackline/
     
    Thomas Hawtin, Dec 19, 2005
    #7
  8. raghu

    Jim Sculley Guest

    Thomas Hawtin wrote:
    > Chris Smith wrote:
    >
    >> Thomas Hawtin <> wrote:
    >>
    >> I've been working in Java since the summer of 1997, and I don't recall
    >> its ever being particularly fast. Not that I write much code that
    >> calls it.

    >
    >
    > I have a memory of a thread posted hereabouts around the 1.2->1.3 era
    > (possibly) revolving around, IIRC, an image process library. The code
    > slowed down significantly when upgrading. IIRC, it turned out that
    > System.gc used to pretty much be ignored if there had just been a
    > significant collection. The code called System.gc often, so with the old
    > version it ignored most of them. However, I can't find anything relevant
    > on groups.google.com.


    http://groups.google.com/group/comp.lang.java.programmer/browse_thread/thread/fe81fa982b09ce67


    --
    Remove my extraneous mandibular appendages to reply via email.
     
    Jim Sculley, Dec 19, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rob Tillie

    Garbage Collector Debugging

    Rob Tillie, Aug 15, 2003, in forum: ASP .Net
    Replies:
    11
    Views:
    1,788
    JerryK
    Aug 18, 2003
  2. Pyramis
    Replies:
    0
    Views:
    427
    Pyramis
    Jan 25, 2004
  3. Colt

    Garbage collector problem

    Colt, Nov 15, 2003, in forum: Java
    Replies:
    9
    Views:
    718
    Tim Ward
    Nov 18, 2003
  4. bart59
    Replies:
    0
    Views:
    520
    bart59
    Jun 17, 2004
  5. Will Hartung

    Garbage Collector Tuning?

    Will Hartung, Sep 8, 2004, in forum: Java
    Replies:
    3
    Views:
    2,124
    Kevin McMurtrie
    Sep 11, 2004
Loading...

Share This Page