English 中文(简体)
列入清单(从、到) 是否允许收集被清除的阿雷拉人部分的垃圾?
原标题:Does sublist(from,to).clear() allow garbage collection of the cleared part of an ArrayList?

在 Java,有一些非致命的ArrayList确实这样做。

list.sublist(from,to).clear()

edit (refactored question):

减少ArrayList的内部规模(即让ArrayList在之后使用较少记忆)?

我特别关心的是,从0到零,即从一开始就将清单清理到某些项目。 如果从清单上的任何指数(而不仅仅是第一个指数)来看,三氯胺(Size)是否也可行?

最佳回答

“肌肉”正在将物体移至根基的本土阵列(目标),但它并没有改变阵列。 如果你想要在拆除ArrayList的一些物品后减少阵容,则使用三维(Size)方法。

阵列中未使用的内容被定为无效,因此可以收集垃圾。

问题回答

When you clear a sublist, its the same as removing those entries, so all of them could be GCed (less they are referenced somewhere else)

The whole point of managed memory objects is that you don t need to worry about how and when they are cleaned up. I wouldn t worry about it unless you know you have a problem. In which case I would use a memory profiler to determine why objects are being retained when you think they shouldn t.

<>>Does sublist (from,to.clear()允许收集已清除的阿雷拉那部分人垃圾?

是的,如果获得一个子名单并明确,请将该子名单上的所有内容从原来的删除。

换言之,如果名单是唯一一个储存物体的条目,你删除的物体有资格获得垃圾收集。

基本原理:

List<String> strings = new ArrayList<String>();
strings.add("one");
strings.add("two");
strings.add("three");
strings.add("four");

System.out.println(strings);   // prints [one, two, three, four]

strings.subList(1, 3).clear();

System.out.println(strings);   // prints [one, four]

未使用 这份返回名单是原件的要人。 如果你修改,则可能出现变化。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...