Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why two gc() method ?

 
Ajit Amitav Das
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15490
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
vidya sagar
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, but note that Peter's contribution is by far the most important in this thread: don't call either version of the method.
 
shan sundaram
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.gc() is static method and invoking the gc by using Runtime.getRuntime().gc();
So, No preference.
 
Ajit Amitav Das
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks u all guys.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic