public class ConvinceGC
extends java.lang.Object
implements java.lang.Runnable
this class should not be necessary, but I did not find a better way to get the GC release memory to the operating system.
When using java
with the option
-XX:MaxHeapFreeRatio
, a successfull GC freeing huge
percentages of memory does not immediately result in deallocation
of memory. My experiments show that several (5–10) calls to
the GC are necessary before memory is really given back to the
operating system to comply with the given
MaxHeapFreeRatio
.
A typical use is
new Thread(new ConvinceGC(10)).start();
which starts a new thread that calls the garbage collector 10 times and then exits.
Constructor and Description |
---|
ConvinceGC(int count)
get a thread which, after being started, calls the garbage
collector the given number of times with an interval of 1 second
in between.
|
Modifier and Type | Method and Description |
---|---|
void |
run()
is only public to satisfy the
Runnable interface,
so rather wrap an object of this class in a Thread
and call its start() method. |
ConvinceGC |
setLogging(java.io.PrintStream out)
after every call to gc, report the amount of memory allocated,
used and the resulting percentage of free memory.
|
public ConvinceGC(int count)
get a thread which, after being started, calls the garbage collector the given number of times with an interval of 1 second in between.
You need to call the start()
method to get things
going.
public ConvinceGC setLogging(java.io.PrintStream out)
after every call to gc, report the amount of memory allocated, used and the resulting percentage of free memory.
public void run()
is only public to satisfy the Runnable
interface,
so rather wrap an object of this class in a Thread
and call its start()
method.
run
in interface java.lang.Runnable