Jonathan Halliday wrote:
I'm looking for a way to force garbage collection to run, as
I need it in order to write meaningful memory leak tests.
As far as I can tell, there is no way for force gc from
inside the jvm, short of hacks like allocating all the
remaining free memory.
The best I can come up with so far is a bit of native code
to call gc via the jvmti. This is a pain, as it means
compiling for every test platform.
We have a classloader leak test in the AS that does both of the above.
The former caused all kinds of hudson issues, usually because the JVM
gets into strange states/dealys when you repeatedly fill all heap space.
The latter however works very reliably. The solution to the portability
problem is IMO, to separate the leak testing from the main testsuite,
and then run that on a dedicated platform. If you have a real Java
memory leak, it should show up on every OS, but probably not every JVM.
Jason T. Greene
JBoss, a division of Red Hat