aspose file tools*
The moose likes Java in General and the fly likes System.gc()? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "System.gc()?" Watch "System.gc()?" New topic
Author

System.gc()?

Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
I write the small program that uses System.gc() function. This program is below
class Garbage {
public static void main(String arg[]) {
System.out.println("Hello");
System.gc();
System.out.println("Hello");
}
}

C:\JavaProgram>java -verbose:gc Garbage
Hello
[Full GC 156K->96K(1984K), 0.0229532 secs]
Hello
What the line means C:\JavaProgram>java -verbose:gc Garbage
Hello
[Full GC 156K->96K(1984K), 0.0229532 secs]
Hello
?
Thanks a lot
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Mike
The line
C:\JavaProgram>java -verbose:gc Garbage
Is what you typed in to run the program:
C:\JavaProgram> is the command prompt.
-verbose:gc is the command to the VM to trace the garbage collection and print it to the screen - that's where the line:
[Full GC 156K->96K(1984K), 0.0229532 secs]
comes from.
And
Garbage is the name of your program of course.
Try to run it without the verbose switch and the trace line will dissapear.
hope that helped


Dave
Mike Shn
Ranch Hand

Joined: May 26, 2001
Posts: 149
ok .. but how I have to understand the line?
Full GC 156K->96K(1984K), 0.0229532 secs]
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

Originally posted by Mike Shn:
ok .. but how I have to understand the line?
Full GC 156K->96K(1984K), 0.0229532 secs]

I'm pretty sure its: 156K is the size of your memory BEFORE Garbage collection, 96 K after, of a total of 1984K. The GC took .0229532 seconds to complete.
Verbose GC is a nice thing to use when you think you might have a memory leak -- We found a bug in JDK 1.3 once that 'caused a memory leak with our EJBs the before/after numbers started getting closer and closer until they were identical and the GC was called every second trying in vain to get some space cleared up.
 
wood burning stoves
 
subject: System.gc()?