• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

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

 
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()
 
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()
 
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 ;-)
 
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
 
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.
 
    Bookmark Topic Watch Topic
  • New Topic