https://kotlinlang.org logo
#announcements
Title
# announcements
i

iex

06/19/2017, 9:47 PM
hello… is there a way in Kotlin to detect when an instance of a class has been deallocated?
d

diesieben07

06/19/2017, 9:49 PM
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
5 Views