| Author |
why two gc() method ?
|
Ajit Amitav Das
Ranch Hand
Joined: Dec 14, 2005
Posts: 49
|
|
HI to all here, i have a doubt why sun has placed 2 gc() method , one in Runtime class and another one in System class , is there any difference between them and which one should have more preference over other and why?
|
Warm Regards<br />Ajit Amitav Das<br />SCJP 1.5
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14670
|
|
From the API: The call System.gc() is effectively equivalent to the call: Runtime.getRuntime().gc() So, no preference. The fact that System's gc() is static makes it easier to call
|
[My Blog]
All roads lead to JavaRanch
|
 |
vidya sagar
Ranch Hand
Joined: Mar 02, 2005
Posts: 580
|
|
Calling gc() method in both classes have same effect. Only difference is gc method in System class is static and not static in Runtime class
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12907
|
|
If you look at the documentation of System.gc(), it says: The call System.gc() is effectively equivalent to the call: Runtime.getRuntime().gc() And if you look at the documentation of Runtime.gc(), it says: The method System.gc() is the conventional and convenient means of invoking this method.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
|
|
Originally posted by vidya sagar: Calling gc() method in both classes have same effect.
... which can be no effect at all (read the API). Calling gc() is very rarely necessary. Java usually works out when to do GC, with no assistance from the application programmer.
|
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
|
 |
vidya sagar
Ranch Hand
Joined: Mar 02, 2005
Posts: 580
|
|
Hi peter Calling gc() method in both classes have same effect. Here i am not talking about things actually done by gc() method and its effectivess on GC functioning. i am saying this The call System.gc() is effectively equivalent to the call: Runtime.getRuntime().gc() in my words. If my words doesn't make correct sense,sorry for what i did.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24045
|
|
|
Indeed, but note that Peter's contribution is by far the most important in this thread: don't call either version of the method.
|
[Jess in Action][AskingGoodQuestions]
|
 |
shan sundaram
Greenhorn
Joined: Feb 07, 2004
Posts: 15
|
|
System.gc() is static method and invoking the gc by using Runtime.getRuntime().gc(); So, No preference.
|
 |
Ajit Amitav Das
Ranch Hand
Joined: Dec 14, 2005
Posts: 49
|
|
|
Thanks u all guys.
|
 |
 |
|
|
subject: why two gc() method ?
|
|
|