File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Difference between Runtime.gc() and System.gc() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Difference between Runtime.gc() and System.gc()" Watch "Difference between Runtime.gc() and System.gc()" New topic
Author

Difference between Runtime.gc() and System.gc()

vitthal wable
Greenhorn

Joined: Sep 09, 2006
Posts: 16
Can You please tell me the difference between Runtime.gc() and System.gc()
Ta Ri Ki Sun
Ranch Hand

Joined: Mar 26, 2002
Posts: 442
No difference at all.

From javadoc :
The call <code>System.gc()</code> is effectively equivalent to the call: Runtime.getRuntime().gc()
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
The difference is that you shouldn't call either of them ;-)


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Marcus Hathaway
Ranch Hand

Joined: Jun 07, 2005
Posts: 89
Hi Peter, why shouldn't you call them?

ps....thats not a loaded question, i'm interested to learn more
Robert Hill
Ranch Hand

Joined: Feb 24, 2006
Posts: 94
For starters calling .gc() does not guarantee that the gc will run at that time. It makes a "best effort" attempt and cleaning unneeded objects.

The second reason is that the gc is a resource hog. Adding the call in your code adds overhead and isn't even necessary. The GC does its job well.

The amount of times that a developer will actually need to mess with the gc or call it directly are rare.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Difference between Runtime.gc() and System.gc()