I’ve read in many threads that it is impossible to turn off garbage collection on Sun’s JVM. However, for the purpose of our research project we need this feature. Can anybody recommend a JVM implementation which does not have garbage collection or which allows turning it off? Thank you.
Share
The simple way to do this is to run the JVM with a heap that is so large that the GC never needs to run. Set the
-Xmxand-Xmsoptions to a large value, and turn on GC logging to confirm that the GC doesn’t run for the duration of your test.This will be quicker and more straightforward than modifying the JVM.
(In hindsight, this may not work. I vaguely recall seeing evidence that implied that the JVM does not always respect the
-Xmssetting, especially if it was really big. Still, this approach is worth trying before trying some much more difficult approach … like modifying the JVM.)Also, this whole thing strikes me as unnecessary (even counter-productive) for what you are actually trying to achieve. The GC won’t throw away objects unless they are garbage. And if they are garbage, you won’t be able to use them. And the performance of a system with GC disabled / negated is not going to indicative of how a real application will perform.
UPDATE – From Java 11 onwards, you have the much simpler option of using the Epsilon (no-op) garbage collector; see
You add the following options when you launch the JVM:
When the heap is filled, no attempt is made to collect garbage. Instead, the Epsilon GC terminates the JVM.