Saturday, 14 September 2013

Setting objects in an ArrayList to null

Setting objects in an ArrayList to null

If I was to have an ArrayList of objects, and I set a few of them to null,
are they susceptible to gc? Or will they stay since they are still being
referenced by the ArrayList
ex:
for(NPC n : NPCs){
n.act();
n.draw(frame);
if(n == outOfMap){
n = null;
}
}
If that loop is "always" being iterated over, will the outOfMap objects be
collected? or simply stay there will a null value?

No comments:

Post a Comment