This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
vitthal wable
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can You please tell me the difference between Runtime.gc() and System.gc()
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1970
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The difference is that you shouldn't call either of them ;-)
 
Marcus Hathaway
Ranch Hand
Posts: 89
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peter, why shouldn't you call them?

ps....thats not a loaded question, i'm interested to learn more
 
Robert Hill
Ranch Hand
Posts: 94
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic