Finalizer being run while class still in use (escape analysis bug)
aph at redhat.com
Wed Oct 10 09:05:58 UTC 2018
On 10/10/2018 01:27 AM, Luke Hutchison wrote:
> Obviously having a garbage collector run a finalizer run while methods of
> the object are still running is a very serious bug.
It's not, it's expected behaviour. Methods are not tracked for
liveness analysis and as soon as an object is garbage collected its
finalizer may be called. See
You will have to makes sure that there is a reachabilityFence
invocation after any calls which require an object to be kept alive.
The problem with using finalizers is that finalizers may be run too
soon (as here,) too late, or never. The "never" possibility really
does happen: sometimes a generational collector moves objects to the
old generation, and as long as there is little memory pressure only
the young generations are collected. You may run out of file handles
long before you run out of memory.
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671
More information about the jdk-dev