The former caused all kinds of hudson issues, usually because the JVMgets 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.
JBoss Profiler has something there to force memory leaks for you via jmti.
You could inject a rule that invokes the GC when a certain method is
invoked or condition exists?
Byteman is ridiculously easy to setup and use, especially for testing
Take a look at
to see it in use.