Ah no
If you’ve ever had the joy of dealing with Java’s garbage collection you’d never get it wrong
What I like about reference counting is that destruction of an object is VERY deterministic.
Last reference is gone the object is cleaned up right then.
Not so with Java’s garbage collection. There’s no “destructor” but a “finalizer”
The runtime periodically runs a thread to find all objects that cannot be referenced from your app and finalizes them at that point. It’s like your destructor runs “some time later” - not when the last reference is gone.
That can lead to some interesting issues.
There are ways to force that thread to run ASAP but you really shouldn’t have to.