kotlin - 如何释放非空变量以进行内存泄漏保护
问题描述
我不知道如何在 Kotlin 中释放对象的非空变量。下面的代码是一个 TextView 列表。它被初始化为非空对象。
class aaa{
var DenomList: MutableList<TextView> = mutableListOf()
var DenomPCSList: MutableList<TextView> = mutableListOf()
var DenomAmountList: MutableList<TextView> = mutableListOf()
var DenomNotationList: MutableList<TextView> = mutableListOf()
var DenomAmountNotationList: MutableList<TextView> = mutableListOf().
}
我想释放上述代码中的对象进行垃圾回收,以保护 Kotlin 中的内存泄漏。请给我一些信息。
解决方案
为了使对象符合垃圾回收条件,下面列出了几个选项:
1) 移除不再使用的特定元素。例如:
list.remove
2)清除列表中的所有元素
list.clear
3)使整个列表分配给null(如果适用,在更改为可空类型之后)
你需要用来制作一个合适的。
推荐阅读
- jquery - 使用 colspan 在 jquery 数据表中的每 n 行之后显示广告图像
- python - 如何通过 2 个列表优化查找值的迭代速度?
- jquery - JQuery 验证金额 xxx.xx
- matlab - 相同的代码在 Mathematica 中有效,但在 Matlab 中无效
- javascript - 灵活的功能 | 用一种功能修改任何变量
- computer-vision - 使用预计算特征在 PCL 中进行点云配准
- php - 静态方法中 splat 运算符的默认参数值
- forgerock - 带删除操作的 Livesync 不起作用
- intellij-idea - intellij 代码格式:less
- python - 将两个从范围创建的列表与不同的步骤结合起来,并为一定数量的索引重复值