• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to force garbage collection in jdk 1.5

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Baiju Varugese
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if jconsole or the profiler can force the garbage collection why not the programmer ?
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic