rspec/rules/S1215/description.adoc

11 lines
795 B
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
Calling ``++System.gc()++`` or ``++Runtime.getRuntime().gc()++`` 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:
2020-06-30 12:47:33 +02:00
* Will the whole application be frozen during the call?
* Is the ``++-XX:DisableExplicitGC++`` option activated?
2020-06-30 12:47:33 +02:00
* Will the JVM simply ignore the call?
* ...
2021-01-27 13:42:22 +01:00
Like for ``++System.gc()++``, there is no reason to manually call ``++runFinalization()++`` to force the call of finalization methods of any objects pending finalization.
2021-02-02 15:02:10 +01:00
2021-01-27 13:42:22 +01:00
An application relying on these unpredictable methods is also unpredictable and therefore broken. The task of running the garbage collector and calling ``++finalize()++`` methods should be left exclusively to the JVM.