aspose file tools
The moose likes Java in General and the fly likes How to force garbage collection in jdk 1.5 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How to force garbage collection in jdk 1.5" Watch "How to force garbage collection in jdk 1.5" New topic
Author

How to force garbage collection in jdk 1.5

Baiju Varugese
Ranch Hand

Joined: Dec 16, 2003
Posts: 74
can we force the garbage collection in jdk 1.5, i got this doubt while profiling my application in the profiler i have an option to force garbage collection, then the user memory got reduced more than 50% so if there is a way to force the garabage collection, i can run a thread that monitor the used memory if the memory reaches certian level i can fore the garbage collection

thanks in advance

baiju


Measure twice cut once carpenter theory <br /> <br />Baiju <br />SCJCP, SCBCD, IBM-486, IBM-484, SCEA Part I
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12911
    
    3

There is no way to force garbage collection using the normal Java API.

If you're really desparate to do this, you could maybe do it by issuing a call to the JVM via the Java Virtual Machine Tool Interface. With Java 5, you get the tool jconsole (try running it from a command prompt) which you can use to keep an eye on how a JVM is doing, and it also has a button to force garbage collection somewhere. See the documentation of jconsole and the page Using jconsole.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Baiju Varugese
Ranch Hand

Joined: Dec 16, 2003
Posts: 74
if jconsole or the profiler can force the garbage collection why not the programmer ?
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12911
    
    3

Because there is no method in the standard API to force garbage collection.

As I already wrote above, it is possible by sending a special call to the VM using the JVMTI (for more information, follow the link in my post above).

If you want to know why there is no method in the standard API to force garbage collection: Normally it is not a good idea to mess with garbage collection. The garbage collection algorithms built-in into the JVM are very smart and efficient, and it is under normal circumstances not necessary to interfere with them - that might even make garbage collection work less efficiently. So to discourage programmers to mess with garbage collection, there's no API method to force garbage collection.
[ November 24, 2005: Message edited by: Jesper de Jong ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to force garbage collection in jdk 1.5
 
Similar Threads
Forcing Garbage collection
Netbeans forces Garbage collection ,not request Garbage Collection
GC is platform dependent?
Garbage Collection
Performance of JBoss