Garbage Collection

Assume we add an object into an ArrayList like thislist.add(new Integer(10));when will the "new Integer(10)" object get garbage collected? there is already no reference for it and if list object gets garbage collected, are the objects it contains also garbage
[297 byte] By [relaxedgalaxya] at [2007-11-27 8:24:07]
# 1

> Assume we add an object into an ArrayList like this

>

> list.add(new Integer(10));

>

> when will the "new Integer(10)" object get garbage

> collected? there is already no reference for it

Not true. The list is referencing the object.

> and if list object gets garbage collected, are the

> objects it contains also garbage collected

Depends on if somethings else references them or not.

kajbja at 2007-7-12 20:13:05 > top of Java-index,Java Essentials,Java Programming...