Time to retire System.runFinalizersOnExit?
mandy.chung at oracle.com
Wed Jan 28 02:44:58 UTC 2015
On 1/27/2015 1:49 AM, Aleksey Shipilev wrote:
> On 27.01.2015 07:37, Mandy Chung wrote:
>> System.runFinalizationOnExit has been deprecated since 1998 (JDK 1.2)
>> and this method is inherently unsafe. I am thinking to propose this method
>> in JDK 9 to throw UnsupportedOperationException.
>> I believe it's rare for existing applications using
>> My analysis on Maven Central ~315K artifacts that show about ~15 unique
>> artifacts calling System.runFinalizationOnExit while they all come from
>> only 5 classes.
> I think while the use case for runFinalizationOnExit(true) is weird to
> begin with, there seems to be a valid reason to enforce the finalizers
> to run at the end, e.g. to properly free the *critical* underlying
> resources. At this point rFOE(true) trick is, while unsafe, still
> operational, right? If we are to remove rFOE(true) escape hatch, what do
> we propose users to do?
The strong references would have to convert to use WeakReference
together with System.runFinalization() or System.gc() -
GcFinalization-like mechanism as Martin suggests.
More information about the core-libs-dev