• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Garbage Collector and System.gc()

 
Ranch Hand
Posts: 65
Android Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It is said Java garbage collector can not be forced and there is no guarantee even if we use System.gc()

My question is if there is no guarantee, then why do we need such a method?

I'd like to know what exactly happens once System.gc() is called?

Thanks in advance,
Renjith
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, technically speaking, System.gc() would call the Runtime().gc() which would pass on the implementation as native to the JVM. So, in short, its all upto the JVM vendor and his choice of implementation how the garbage collection would work...
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tushar bhasme wrote:well, technically speaking, System.gc() would call the Runtime().gc()



not Runtime().gc(), it is Runtime.getRuntime().gc();
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The main objective of Garbage Collector is to destruct the useless objects. Garbage Collector is a DeamonThread and it always running in the background with low thread priority. If an object doesnt have any reference variable then it always eligible for GC( some times even though object having reference also it is eligible for GC)
If an Object eligible for Gc and when ever JVM runs garbage collector then only that objects will destroyed.

we can also request to JVM to run GC in the followin ways
1.System.gc();
2.Runtime.getRuntime().gc();

the behaviour of garbage collector vendor dependent hence we cant expect exactly when JVM executes GC, in wich order GC destroys the objects, is Gc destroy all eligible objects... etc

there are so many things remaining about garbage collection, digg the things..
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic