views:

1470

answers:

4

Hi.

how could I request Java garbage collection externally, starting the program from JAR (Windows BAT used)?

  • From the Java code I can do it with System.gc()
  • When running a JNLP distribution, I get this "Java console" turned on from Control Panel / Java / ... and this Java console provides manual garbage collection.

But... When I'm running the jar from command-line / bat the java console doesn't seem to open. Couldn't find help with a brief googling, maybe somebody here?

+3  A: 

You can use jconsole to connect to a JVM that is running locally - This provides a "Perform GC" button on the GUI.

You'll need to specify -Dcom.sun.management.jmxremote when you kick off your java process.

Peter
Thanks, seems to work fine!
Touko
+1  A: 

If you use the very latest java 6 you also have jvisualvm which complements and extend the jconsole functionality. They are both very useful tools.

Thorbjørn Ravn Andersen
A: 

You should also be able to do this programatically with the JNI interface.

QuickRecipesOnSymbianOS
+2  A: 

You normally should not have any reason to force garbage collection. Doing so, messes up the garbage collector algorithms (mainly their performance). It will also slow down the program while garbage is being collected. If there is a memory issue, you should use memory tracing tools to find out where references are being held? (Are listeners unregistered?)

Paul de Vrieze