Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Garbage Collection Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Garbage Collection" Watch "Garbage Collection" New topic

Garbage Collection

Sharada Kumaran

Joined: May 23, 2001
Posts: 29
I have read in some places that Garbage Collection in java cannot be forced. If this is true, what does System.gc() do?
What does Runtime.gc() do?

Jonathan Jones

Joined: Apr 26, 2001
Posts: 6
System.gc() or Runtime.gc() simply make a tentative call to run the garbage collector. They do not force at all the garbage collector to be run. Thus the garbage collector may or may not run, but you can never be sure
Samith Nambiar
Ranch Hand

Joined: Mar 14, 2001
Posts: 147
a small correction ... that would be Runtime.getRuntime().gc()
this is because gc() is not a static method
I agree. Here's the link:
subject: Garbage Collection
It's not a secret anymore!