Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

System.gc()?

 
Mike Shn
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mike Shn
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok .. but how I have to understand the line?
Full GC 156K->96K(1984K), 0.0229532 secs]
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic