java - 当函数在 android 中结束时清除 map 是否值得?

标签 java android

在 android 中,我使用 hashmaps 和 sparsearrays 和 sparseintarrays。在我使用的函数中,它们有时是临时对象。在函数结束之前,是否清除 map 数据是一个好习惯?

谢谢

最佳答案

In android, I make use of hashmaps and sparsearrays and sparseintarrays. In functions I use them sometimes are temporary objects. Before the function ends, it is a good practice to clear the map's data or not?

不,那什么也做不了。

I thought, if you clear it, then you get back the memory right away instead of waiting for garbage collection. So doesn't that make it work it?

清除集合只会清除对集合中项目的引用,因此您仍然需要等待垃圾回收来取回内存。

关于java - 当函数在 android 中结束时清除 map 是否值得?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25612363/

相关文章:

java - 扫描仪 : java. util.Scanner.next(来源未知)问题

java - 如何创建元素并设置自定义属性以映射简单类型类属性

android - 如何从日历中获取所有事件?

android - 如何只为按钮添加底部阴影

javascript - Android Web-View : Inject local Javascript file to Remote Webpage

java - Android:在按钮上使用九色补丁背景,我无法在文本周围添加任何填充

java - 为什么会出现InflateException(由ClassNotFoundException引起)?

java - 梯度错误: Could not find property file

android - react 原生 : changing minSdkVersion from 21 to 23 doubled the app apk size

java - 通过选择进行排序