top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Why the method call System.gc() doesn't guarantees that the Garbage Collector algorithm will run at that moment?

+2 votes
418 views
Why the method call System.gc() doesn't guarantees that the Garbage Collector algorithm will run at that moment?
posted Sep 18, 2013 by Vinay Shukla

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

You have no control over GC in java,the JVM decides. Since a System.gc() call simply means that the JVM do a garbage collection and it also does a FULL garbage collection (old and new generations in a multi-generational heap) then it can actually cause more cpu cycles to be consumed than necessary.

In some cases, it may make sense to suggest to the JVM that it do a full collection now as you may know the application 'll be sitting idle for the next few minutes before heavy lifting occurs. For example, right after the initialization of a lot of temporary object during application startup . Think of an IDE such as eclipse starting up it does a lot to initialize, so perhaps immediately after initialization it makes sense to do a full gc at that point.

answer Sep 18, 2013 by Arvind Singh
Similar Questions
...