File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes System.gc() vs Runtime.gc() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "System.gc() vs Runtime.gc()" Watch "System.gc() vs Runtime.gc()" New topic

System.gc() vs Runtime.gc()

Pankaj Patro
Ranch Hand

Joined: Apr 20, 2005
Posts: 35
* What is the differance between System.gc() and Runtime.gc() ?

Thanks & Regards,
Pankaj Patro
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
System.gc() is just a convenience for Runtime.getRuntime().gc().

However, if you are genuinely a beginner, you should never be calling either of these methods.

99.9% of the time, Java will garbage-collect as appropriate and does not need you to tell it to do so. Calling one of the gc() methods does not force garbage collection to happen, either; it only suggests to the JVM that now might be a good time for some garbage collection.

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15084

Read the API documentation of both of those methods. The documentation of System.gc() says:

The call System.gc() is effectively equivalent to the call:


So, there is no difference in these two at all.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: System.gc() vs Runtime.gc()
It's not a secret anymore!