【发布时间】:2018-08-16 14:57:49
【问题描述】:
我正在使用 Thread 进行一些异步操作。现在我主要有 3 个线程,例如:
private lateinit var horse1Thread: Thread
private lateinit var horse2Thread: Thread
private lateinit var timerThread: Thread
在onDestroy() 的活动中调用stop() 会导致UnsupportedOperationException,我想将这些值设置为null 以允许GC 收集并防止内存泄漏。由于我的字段是non-null 类型,我无法将它们设置为null。那么this 是我唯一的选择吗?或者 kotlin 是否提供了一种方法来释放这些字段所持有的内存?我可以将它们的类型设置为可为空,但我觉得它违背了目的?
【问题讨论】:
标签: android multithreading kotlin garbage-collection non-nullable