hello… is there a way in Kotlin to detect when an ...
# announcements
i
hello… is there a way in Kotlin to detect when an instance of a class has been deallocated?
d
ischuetz: Same way as in Java, the way to do it would be
finalize
. There are discussions about discussions about why
finalize
is terrible though. You should really use the
Closeable
interface with the
use
function.
👍 1
There is also
WeakReference
/
SoftReference
, which can notify you through a
ReferenceQueue
, but the use-case is extremely limited. It's not a good idea to rely on the garbage collector in this way.
👍 2