Difference between System.gc() and Runtime.getRuntime().gc() [message #710630] |
Fri, 05 August 2011 08:35 |
casperl90 Messages: 5 Registered: August 2011 |
Junior Member |
|
|
Q:-What is the Different between System.gc() and Runtime.getRuntime().gc()?
Answer-System.gc() runs the Garbage Collector.The JVM performs this recycling of all discarded obj's even if gc is not invoked explicitly.It is a static method.
Runtime.getRuntime() returns Runtime obj ass'ted wth the current java appl'n.
Once if we get the Runtime obj on that obj we can call one of the following methods
1)gc();
2)freeMemory();
3)totalMemory();
Most of the methods of Runtime class are instace methods.This is a static method.
Runtime class is a singleton class.we can create Runtime obj by using Factory method.
but System.gc() is equivalent to Runtime.getRuntime().gc()
and System.gc() is the most conventional and convenient method.
|
|
|
Powered by
FUDForum. Page generated in 0.07226 seconds