File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Diff b/w System.gc() VS Runtime.gc()

 
vidya sagar
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI FREINDS

Can any one specify the differences between System.gc() and Runtime.gc()

Thanks in advance....
 
Jay Pawar
Ranch Hand
Posts: 411
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe both do the same task of "suggesting" garbage collecter to run.
However, gc() method is static in System class and non-static in the Runtime class.

System.gc() // static method gc in System class

For Runtime you have to do something like this



Hope that helps...
 
Jeff Jetton
Ranch Hand
Posts: 71
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From Sun's API documentation:


System

public static void gc()

Runs the garbage collector.

Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects.

The call System.gc() is effectively equivalent to the call:

Runtime.getRuntime().gc()




And...


Runtime

public void gc()

Runs the garbage collector. Calling this method suggests that the Java virtual machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the virtual machine has made its best effort to recycle all discarded objects.

The name gc stands for "garbage collector". The virtual machine performs this recycling process automatically as needed, in a separate thread, even if the gc method is not invoked explicitly.

The method System.gc() is the conventional and convenient means of invoking this method.


- Jeff
 
Tony Morris
Ranch Hand
Posts: 1608
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no difference. One is a level of indirection for the other.
In most implementations, System.gc() merely calls Runtime.gc().

And of course, you have to throw in the ambiguity in the API Spec. just to confuse people, otherwise, it just wouldn't be Java now, would it?.
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"vidyasagar"-
Welcome to the JavaRanch! Please adjust your displayed name to meet the

JavaRanch Naming Policy.

You can change it

here.

Thanks! and welcome to the JavaRanch!

Mark
[ April 08, 2005: Message edited by: Mark Spritzler ]
 
Raghu Shree
Ranch Hand
Posts: 143
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,
Why r u always suggest to change the display name. I saw this message in every post
 
vidya sagar
Ranch Hand
Posts: 580
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi mark

I hope now u Satisfy

Rather than telling each person to change Ur name to naming policy

Better u Validate while creating R updating profile
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic