これはデータ プロバイダーです。
class Item {
private String text;
public Item(String txt) {
this.text = txt;
}
public String get() {
return this.text;
}
public static Item next() {
return new Item("hello");
}
}
今、私はこれをやろうとしています(それがどのように機能するかを理解するための単なる例です):
List<String> texts = new LinkedList<>();
for (int i = 0; i < 10000; ++i) {
Item item = Item.next();
texts.add(item.get());
}
// do we still have ten thousand Items in memory,
// or they should already be garbage collected?
GC がすべてのオブジェクトを破棄するのか、それともオブジェクトのパーツへの 10000 個のリンクを保持しているItem
ため、オブジェクトがメモリに残るのか疑問に思います ( )。List
text