When does garbage collection occur?

Answer the question!
thanks

Sometime after a objects become unreachable and before the memory allocator runs out of memory, the garbage collector will run. You have no way of controlling or knowing when that will be. There is no reason to.
For some reason, even though many programming languages have garbage collection, people seem to regard Java's garbage collection as something they need to "understand" and control. Garbage collection is best left up to the garbage collector -- that's its job, and just let it work.

Similar Messages

  • How to specify when Full Garbage Collections occur in the Old Generation

    Hi. We seem to be having a problem with a number of JVMs (1.5.0_17-b04) that run a component of a Document Management application. This component stores a large amount of information in caches which reside in the Old Generation. Although these cache sizes can be somewhat controlled by the application, they are currently taking about 85% of the Old Generation space. Fortunately, very few objects get tenured into the Old Generation - they all are cleaned up in the New Generation space.
    The problem we are seeing is that with the Old Generation at 85% full, there are constant full GC's occurring. Since the caches cannot be removed, the system frantically tries to remove objects that can't be removed.
    We have three solutions in mind. The first is to increase the memory allocation to the Old Generation so that the caches take a smaller percentage of the available memory allocation. The second would be to decrease the size of the caches; but this is set more by the number of documents in the application and cannot be made much smaller.
    The third solution is to configure the JVM so that Garbage Collections in the Old Generation do not occur until the memory is more than a specific percentage of memory in the Old Generation. We would then set this percentage to be higher than the amount of memory being used by the caches.
    So, is it possible to tell the JVM to only run a Full GC when the memory in the Old Generation is greater than a specific value (say 85% full)?
    Thanks for your help.
    Andre Fischer.

    afischer wrote:
    The third solution is to configure the JVM so that Garbage Collections in the Old Generation do not occur until the memory is more than a specific percentage of memory in the Old Generation. We would then set this percentage to be higher than the amount of memory being used by the caches.
    So, is it possible to tell the JVM to only run a Full GC when the memory in the Old Generation is greater than a specific value (say 85% full)?Switch to the CMS collector.
    -XX:+UseConcMarkSweepGC
    -XX:CMSInitiatingOccupancyFraction=86

  • Garbage collection time change

    Hello how can i find out exactly when does garbage collection take place for my managed servers heap size and how can I optimize it and have garbage collection done at an earlier stage?

    Hi,
    You can use vm startup params -Xverbose:gcpause and -Xverboselog to trace and log gc events.
    For example, java -Xverbose:gcpause -Xverboselog:verboseText.txt myApp

  • Runtime.getRuntime().exec() and Garbage Collection

    I am programming a piece of software in both Java and C that has some strict real time requirements. Garbage collection, which pauses all threads in Java, sometimes causes loss of incoming data. In order to get around this, I am thinking to start another process using Runtime.getRuntime().exec("c_program") and using interprocess controls (in a UNIX environment) to retrieve data from the new process.
    My only worry is that the Process created by the above call would be a child process of whatever JVM thread created it, (as far as I understand, the JVM implementation in Unix uses multiple processes) and would also be paused when garbage collection occurs. Does anyone know the implementation of the exec functionality and the JVM well enough to say that this will or will not happen?
    Thanks in advance,
    Benjamin

    You're going to create a whole new process? I don't
    know what a "child process" means, but Runtime.exec()
    gets the operating system to produce an entirely new
    process, outside the JVM. However if it produces
    output on stdout or stderr, you're going to have
    threads in your JVM that read that output, otherwise
    that process will hang.
    Why is your idea better than just calling the C
    program via JNI?Thank you both for your replies. My plan was to create a whole new process, yes. In UNIX, a process C is created by another process P using fork() or the exec() family. Process P is then the parent of process C, and process C is the child of Process P. P has an amount of control over C since it can send various signals to pause, kill, etc to C.
    My concern was that the JVM implementation would use these signals to implement the pause of all threads before garbage collecting. If it did, it may also pause the Process that it spawned from the Runtime.exec() call. Pausing my C program in this manner would cause the loss of data I was trying to avoid in the first place.
    My plan for the new process was not to produce anything on stdout or stderr, but to pass data back to the JVM using ipc (interprocess communication) resources of UNIX. I would have to use the JNI to access these resources.
    The whole reason for wanting to do this is to avoid the pause during garbage collection that all Java Threads experience. If I were just to call the C program through the JNI with a normal Java Thread as I think you were suggesting, this Java Thread would still be paused during garbage collection.
    To the second reply about RTSJ, I had heard about this but couldn't find info about it! Thanks for the link. I'm checking it out at the moment. The java runtime must be considerably different for the specifications I see that they guarantee.
    Again, thanks for the replies,
    Benjamin

  • Understanding Garbage Collection

    Garbase Collector collects any objects that the program cannot access. If an object cannot be accessed, it will be collected by the garbage collector if needed.
    Can someone explain with a simple example when an object cannot be garbase collected? preferably an example with 'String'
    thanks

    String text = "Hallo";
    //the instance "Hallo" cannot be collected here
    String message = text;
    text = null;
    //neither here;
    message = null;
    //The instance "Hallo" can be collecter here by the GBI don't think that this is the way it works. Garbage collection frees memory for use, and in this case, the variable text could still be referenced, even though it does not have a value. I might be wrong, but my guess would be that setting a variable to be null, would result in the location of memory allocated for the variable to be emptied (e.g. C-function memset). If the garbage collection would occur when the variable is set to null might cause problems, like so:
    String foo = "bar; // Create and initliaze variable
    foo = null; // Set to null, assume garbage collection
    String bar = "foor"; // Create and initialize. If this were now stored
    // in the same memory slot as foo, which would be possible due
    // to the garbage collection, problems would arise from next line
    foo = "bar"; // Now foo and bar refer to the same memory locationTherefore garbage collection occurs only when no object or class holds no reference to the variable, example:
    if(foobar) {
       String localVar = "local variable";
    // When the if-block ends, the variable localVariable is collected
    // as it no longer can be referenced.Tuomas Rinta

  • Getting memory dump without garbage collection

    Hi all.
    Does anyone know of a way to get a memory dump from the Sun JVM (version 1.5.0_11 for Windows) without garbage collection occurring first? I've tried the -XX:+PrintClassHistogram option, but this always seems to garbage collect before printing the histogram.
    My problem is that I see heap usage increasing very rapidly in the JVM, then garbage collection occurs and reduces memory usage back down to what it was before. However, this results in the JVM spending a large amount of time garbage collecting. I would like to be able to see the contents of the heap before GC occurs.
    These are the options I've tried so far:
    * Using -XX:+PrintClassHistogram. As mentioned above, this always garbage collects before printing the histogram.
    * Using -XX:+HeapDumpOnOutOfMemoryError. The problem is that the JVM always manages to GC before running out of memory, so never dumps the heap.
    * Using the jmap tool. Unfortunately I'm running Windows (in production), so this is not available for 1.5.
    * Using HPROF. However this seems to slow the JVM down hugely (whenever I use -agentlib:hprof=heap=sites or -agentlib:hprof=heap=dump).
    * Using the HeapViewer demo tool that comes with the JVM. This has the same effect as PrintClassHistogram and garbage collects before outputting.
    * Using JProfiler. Unfortunately it seems (with the 1.5 JVM anyway) the Concurrent Garbage Collector cannot be used in conjunction with JProfiler (I think this is a JVM TI issue?). With the Parallel GC we don't see the same problem (probably mostly because throughput is crippled with the Parallel GC).
    * Using jstat. This only gives us statistics about how much has been garabge collected, not which objects were collected.
    Has anybody got any other suggestions?
    Thanks.
    Neil.

    Hi all.
    Just an update on this -- I couldn't find any way to do this in Java 1.5 (on Windows).
    In Java 1.6 (and maybe in 1.5 on other platforms) jmap will do a heap dump without garbage collecting.
    I also came across an open source memory profiling tool called Ariadna (see http://mernst.org/ariadna/) which seems to work quite well. It was only of limited use in Java 1.5 however, since JVM TI doesn't support the concurrent garbage collector in this version.
    Hope this is helpful anyway. I'll be trying to get upgraded to 1.6 ASAP!
    Thanks.
    Neil.

  • Garbage collection logs

    In the following garbage collection logs:-
    84818.180: [GC 84818.180: [ParNew: 159810K->11632K(172032K), 0.0475511 secs] 520283K->372704K(1024000K), 0.0477481 secs]
    84874.024: [GC 84874.024: [ParNew: 159088K->14118K(172032K), 0.0552993 secs] 520160K->375190K(1024000K), 0.0554933 secs]how would you find out when the garbage collection cycle actually took place? i.e. absolute time

    In the following garbage collection logs:-
    84818.180: [GC 84818.180: [ParNew:
    159810K->11632K(172032K), 0.0475511 secs]
    520283K->372704K(1024000K), 0.0477481 secs]
    84874.024: [GC 84874.024: [ParNew:
    159088K->14118K(172032K), 0.0552993 secs]
    520160K->375190K(1024000K), 0.0554933 secs]how would you find out when the garbage collection
    cycle actually took place? i.e. absolute timeI normally try to update my posts in case somebody in future comes across the same question, he finds an answer to the problem as well and not just the problem. So what I found out was that in the above gc logs, 84818.180 would be the no. of seconds since the start of the appserver, and one would have to get that time from stderr.log file. So once you get that time from stderr log you need to add these sec to that time to get the absolute time. Its kind PIA but thats how it is, I am still not sure why they used this convention since time from start of the server would not mean anything for a developer analyzing the log files

  • Garbage collection of threads

    1. class MyThread extends Thread {
    2. public void run () {
    3. longTermJob();
    4. }
    5.
    6. public static void longTermJob () {
    7. for (int i = 0; i < 10000; ++i) {
    8. System.out.println(i);
    9. try {Thread.sleep(1000);}
    10. catch (InterruptedException) {}
    11. }
    12.
    13. }
    14.
    15. }
    16.
    17. class Test {
    18. public static void main (String[] args) {
    19. new MyThread().start();
    20. MyThread.longTermJob();
    21. }
    22. }
    After execution in line 19, the object of MyThread
    is not referenced by any variables; and hence
    could be destroyed by garbage collection thread.
    My question is :
    When the garbage collection is started and
    detects that the object(MyThread) is no longer
    referenced by anyone and the thread created by
    MyThread object is still in execution, would
    the thread finish successfully or
    stop abnormally?

    My question is :
    When the garbage collection is started and
    detects that the object(MyThread) is no longer
    referenced by anyone and the thread created by
    MyThread object is still in execution, would
    the thread finish successfully or
    stop abnormally?Unless the VM is exited, it will run normally until is finishes. Then if there are no more references to the thread, it will be garbage collected eventually.

  • When playing my ipod on an ipod dock the vocals are very faint. It is fine when doing through the headphones. I am trying to sync for updates and getting the message "An unknown error occured (-1)" - help

    When playing my ipod on an ipod dock the vocals are very faint. It is fine when doing through the headphones. I am trying to sync for updates and getting the message "An unknown error occured (-1)" - help

    Error -1
    Attempt to restore your iOS device two more times. If the issue is still unresolved, the device may need service.
    The "device may need service" means a hardware problem. In that case make an appointment at the Genius Bar of an Apple store.
    Apple Retail Store - Genius Bar
    Also see:
    -1 error
    -1 error too

  • When will wls try to garbage collect ?

    The docs for the option "Low memory GC threshold" say that this is the "Threshold
    level at which WLS will try to garbage collect once the granularity report has
    been met".
    My question is: When is this condition met ? If at least once there has been a
    granularity report in the log ? Or if the server has been set to Warning state
    The problem Im trying to address is that my "Low memory GC threshold" is set to
    20% and my server has reached only 1% free memory and garbage collection did not
    run, I had to force it via console.
    Thanks in advance, Giselle

    I am wonder when the WLS activate or passivate session and how can I          control it?
              > From documents, sessionWillPassivate in HttpSessionActivationListener will
              be
              > executed when a session is about to passivate on one server (ie. WLS
              instance)
              > and the sessionDidActivate method when the same session has been activated
              on
              > a second server.
              >
              > But I have monitor the behavior for a long time by setting
              PersistentStoreType
              > to file, memory, replicated. sessionDidActivate and sessionWillPassivate
              will
              > never executed. I expected it will passivate and activate when session is
              replicated
              > between servers or persist in files. Any ideas?
              What version of WL? the interface you describe was new in Servlet 2.3, so it
              may not be implemented until 6.1 or even 7.x.
              Peace,
              Cameron Purdy
              Tangosol, Inc.
              http://www.tangosol.com/coherence.jsp
              Tangosol Coherence: Clustered Replicated Cache for Weblogic
              "Karen Law" <[email protected]> wrote in message
              news:3ec86188$[email protected]..
              >
              

  • Does Indes stats get auto collected when stats auto collection is on?

    In 10g and 11g, does Index stats get auto collected when stats auto collection is on (by default)? When do we need it? As I saw nothing in INDEX_STATS in both 10g and 11g.
    Thanks.

    Default is FOR ALL COLUMNS SIZE AUTO. statistics for indexes were also collected.
    Index stats will be populated only if you validate structure. The view INDEX_STATS is only populated after you run an analyze index name validate structure. if you log out you no longer see the statistics
    analyze index <index_name> validate structure;
    select * from index_stats;
    You'll see the information.
    Edited by: Anantha on Jan 12, 2009 2:16 PM
    Edited by: Anantha on Jan 12, 2009 2:25 PM

  • Animation gets slow when program needs a Garbage Collect.

    So nonetheless, I should probably develop a new animation algorithm, yes?
    I am looping through a seperate thread that calls the setSize() methods a bunch of times. Works really nice when memory isnt bad, but when I need to garbage collect, and apparantly java doesnt agree, it gets really slow. Later one is really able to see when a GC is actually done, and it goes back to normal.
    Here is my algorithm,
    public static boolean raisePanel(final VCMSComponentFrame p, final boolean anim)
            if (p.getState() == VCMSComponentFrame.State.RAISED ||
                p.getState() == VCMSComponentFrame.State.ANIMATING)
                return false;
            new Thread(new Runnable()
                public void run()
                    p.setState(VCMSComponentFrame.State.ANIMATING);
                    if (anim)
                        for (int i = p.getHeight(); i <= FULL_PANEL_HEIGHT; i++)
                            try
                                p.setSize(p.getWidth(), i);
                                JComponent parent = (JComponent)p.getParent();
                                int index = findIndex(p);
                                for (int j = index + 1; j < parent.getComponentCount() && j != 0; j++)
                                     parent.getComponent(j).setLocation(parent.getComponent(j).getX(), parent.getComponent(j).getY() + 1);
                                //Viewport Panel
                                parent.setSize(parent.getWidth(), parent.getHeight() + 1);
                                //Structure Frame
                                VCMSStructurePanel panel = (VCMSStructurePanel)parent.getParent();
                                parent.getParent().setSize(panel.getWidth(), panel.getHeight() + 1);
                                //Structure Siblings.
                                JPanel master = (JPanel)panel.getParent();
                                index = findStructureIndex(panel);
                                for (int j = index + 1; j < master.getComponentCount() && j != 0; j++)
                                    master.getComponent(j).setLocation(master.getComponent(j).getX(), master.getComponent(j).getY() + 1);
                                Thread.sleep(1);
                            catch (Exception ex)
                    else
                        p.setSize(p.getWidth(), FULL_PANEL_HEIGHT);
                        JPanel parent = (JPanel)p.getParent();
                        int index = findIndex(p);
                        //Viewport Panel
                        parent.setSize(parent.getWidth(), parent.getHeight() + FULL_PANEL_HEIGHT - SHORT_PANEL_HEIGHT);
                        //Structure Frame
                        VCMSStructurePanel panel = (VCMSStructurePanel)parent.getParent();
                        parent.getParent().setSize(panel.getWidth(), panel.getHeight() + FULL_PANEL_HEIGHT - SHORT_PANEL_HEIGHT);
                        //Component Siblings
                        for (int j = index + 1; j < parent.getComponentCount() && j != 0; j++)
                            parent.getComponent(j).setLocation((int)parent.getComponents()[j].getLocation().getX(), (int)parent.getComponents()[j].getLocation().getY() + FULL_PANEL_HEIGHT - SHORT_PANEL_HEIGHT);
                        //Structure Grandparent
                        JPanel master = (JPanel)panel.getParent();
                        index = findStructureIndex(panel);
                        for (int j = index + 1; j < master.getComponentCount() && j != 0; j++)
                            master.getComponent(j).setLocation((int)master.getComponent(j).getLocation().getX(), (int)master.getComponent(j).getLocation().getY() + FULL_PANEL_HEIGHT - SHORT_PANEL_HEIGHT);
                    p.setState(VCMSComponentFrame.State.RAISED);
            }).start();
            //System.gc();
            return true;
        }any help appreciated!

    sierratech wrote:
    Only a guess, but this may have something to do with Threads and Swing.
    http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html.
    Many Swing updates should be called in the Event Dispatch thread, and it looks like you may be calling some of these in your new Thread.
    Try using SwingUtilities.invokeLater() and see if that helps. Alternatively, rewrite your code to remove the Thread and do everything in the event Dispatch thread using javax.swing.Timer. Again, just a guessThanks for the Idea, but this option doesnt even show the animation.
    One Idea I got from a "Swing Hacks" directory works like this:
    Remove the components for animation.
    Create an image of the components.
    Overide the Paint method.
    Animate the images via paint method.
    Remove the images.
    Add back the components.
    But I look at that and my stomach cringes.
    Any other Ideas?

  • Does 5.1 log garbage collection like 4.5.2?

    The weblogic 4.5.2 release notes state that the server will log whenever it
    garbage collects, see below. Does 5.1 do this?
    "We changed the distributed garbage collection server to always indicate
    that it is running by adding entries to the Server log file. A typical entry
    is:
    Thu Aug 19 19:44:28 PDT 1999:<I> <DGCserver>
    Freed 1086 objects in 30 ms, 24 exported object remain."

    It should. There is a slight possibility that it might not appear as a
    feature until service pack No. 4 if the change to version 4.5.2 was not done
    until after service pack three was completed.
    If you do not see it in service pack No. 4, please report to support.
    Thanks,
    Michael
    Michael Girdley
    Product Manager, WebLogic Server & Express
    BEA Systems Inc
    Mark Johnson <[email protected]> wrote in message
    news:396bbb8f$[email protected]..
    The weblogic 4.5.2 release notes state that the server will log wheneverit
    garbage collects, see below. Does 5.1 do this?
    "We changed the distributed garbage collection server to always indicate
    that it is running by adding entries to the Server log file. A typicalentry
    is:
    Thu Aug 19 19:44:28 PDT 1999:<I> <DGCserver>
    Freed 1086 objects in 30 ms, 24 exported object remain."

  • When will garbage will be collected ?

    hi,
    when will garbage will be collected if our class contains static methods and non static methods.
    when it will exactly happen
    thanks in advance.
    regards
    srinivas.

    That is what I am trying to figure out, when are there
    no more references to it based on what i have
    described? As I mentioned, the Thread is added to a ThreadGroup when it is created. In your case the thread can be cleaned up when the Threads has been removed from the ThreadGroup.
    I'm not really sure. Won't there need to be a new thread per request, If you can use one thread to send all the replies (which also need to be serialised) what is special about the requests that they need their own threads. How is the serialization of the requests so fundermentaly different?
    otherwise how will the thread get the object to be serialized,I don't see how the objects are serialized and how you use your threads are releated???
    or is a setRequest(someRequest) on the thread from the model OK to do.I would use another thread that the GUI thread to send requests and recieve replies.
    I was somewhat leery of calling a setter from the model on an already running thread. I would call the setter for the GUI thread.
    How you do this is:
    - Read reply using the thread reading replies.
    - Add a Runnable to the GUI Thread to set the values via SwingUtilities.invokeLater()

  • When will the demo object be eleigible for garbage collection?

    class Test {
         private Demo d;
         void start() {
         d = new Demo();
         this.takeDemo(d);
         void takeDemo(Demo demo) {
         demo = null;
         demo = new Demo();
         }

    Hey flounder, I am myself confused about garbage collection and assertions (yesterday)... Anyway because of ur interest in answering my query, I'll give one more try... But, if it's wrong, Please help me out.
    The Demo (not demo) object created at line 4 has one 'this' reference on the next line. And as soon as this reference is eleigible, I guess even Demo d will be eligible. Correct?

Maybe you are looking for

  • EjbCreate() called multiple times

    I have a Bean Managed Persistence Entity Bean that is deployed on iAS6 sp4 (Solaris). I am having problems with the persistence, or lack of, of the bean. I am new to entity beans but not Java or iPlanet. My first problem is after I call my custom fin

  • IDOC error : Status 52

    Hi Guys, While performing inbound activity with IDOC, getting status message 52 with yellow status. When i am checking for HR master data, infotype 0, 1 and 2 is creating but other infotype 6, 7, 105 and 315 is not being creating and getting the erro

  • I'm getting error (-3259) whilst trying to update to version 4.3.2.

    I'm wondering if anyone can help me here. I try to update my iPhone as it says there is an update available, and it fully downloads. It then tries to verify the download and I get an error (-3259). Can anyone help me with this as it would be greatly

  • Description for fixed assets in english & chinese language

    Hi Our chinese client wants to maintain description for fixed assets in chinese language along with English Can any one let me know how to do this?? Regards, Ajay

  • Distiller and Cooltype.dll error

    Recently updated Acrobat Pro, and now can't convert and files into PDF. Either running the printer option from MS Office or opening Acrobat and creating a "new" PDF. Even CS2 now won't save as a PDF for me. I get an error from Distiller when generati