rspec/rules/S1215/description.adoc

8 lines
598 B
Plaintext
Raw Normal View History

2020-06-30 12:47:33 +02:00
Calling <code>System.gc()</code> or <code>Runtime.getRuntime().gc()</code> is a bad idea for a simple reason: there is no way to know exactly what will be done under the hood by the JVM because the behavior will depend on its vendor, version and options:
* Will the whole application be frozen during the call?
* Is the <code>-XX:DisableExplicitGC</code> option activated?
* Will the JVM simply ignore the call?
* ...
An application relying on these unpredictable methods is also unpredictable and therefore broken. The task of running the garbage collector should be left exclusively to the JVM.