haii..

do anyone know any garbage collection command for java....
did we have to did that command for all object or will be done collectively??

thank u.....

I'm pretty sure it's something along the lines of--

Runtime.getRuntime().gc();

Or the long way--

Runtime rt = Runtime.getRuntime();

rt.gc();

I do believe you can do the same using System instead of Runtime (without calling getRuntime - just System.gc() )


This simply suggests for the Garbage-Collecting threads to begin garbage collecting. It does not mean that it will be immediately done. In that respect, it's not really known when garbage collecting will be done. Lastly, explicitly calling the gc causes additional overhead since the call to gc is suggesting that there are unreferenced objects to collect and the threads are signalled to do extra work and search through all possible objects to garbage collect ones that are reachable and unreferenced.

The process is slightly more complicated than mentioned. This is a watered down and brief explanation.

The garbage collector is very smart. There's hardly ever a need to use the provided commands to SUGGEST it runs.
If you think you need to, you almost certainly have an error somewhere in your code causing excessive memory use that prevents garbage collection by holding on to objects unnecessarilly.

Comments
After learning the hard way in the past, I completely agree.

The garbage collector is very smart. There's hardly ever a need to use the provided commands to SUGGEST it runs.
If you think you need to, you almost certainly have an error somewhere in your code causing excessive memory use that prevents garbage collection by holding on to objects unnecessarilly.

problem solved using System.gc;

Thank you all

This question has already been answered. Start a new discussion instead.