• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
vitthal wable
Greenhorn
Posts: 16
  • 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
  • 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
  • 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
  • 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
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic