I am using Thread for some Async operations. Now primarily I have 3 Threads like :
private lateinit var horse1Thread: Thread
private lateinit var horse2Thread: Thread
private lateinit var timerThread: Thread
Calling stop()
in onDestroy()
of activity causes a UnsupportedOperationException
and I thought of setting these values to null
to allow GC collection and prevent memory leak. Since my fields are non-null
types I cant set them to null
. So is this my only option? Or does kotlin provide a way to free the memory held by these fields? I can set their type to nullable but I feel it defeats the purpose?