No, but if nothing else has reference to them, they will be eligible for garbage collection.
E.g., simpler example:
class Foo {
Date dt;
Foo() {
this.dt = new Date();
}
}
ArrayList<Foo> list = new ArrayList<Foo>();
list.add(new Foo());
list.clear();
As of the clear
, the Foo
object's dt
has not been "nulled" or anything, but the Foo
object and the things only it refers to (the Date
inside it, in this case) are eligible for garbage collection.
Whereas:
class Foo {
Date dt;
Foo() {
dt = new Date();
}
}
ArrayList<Foo> list = new ArrayList<Foo>();
Foo f = new Foo();
list.add(f);
list.clear();
Here, the Foo
object isn't eligible for garbage collection, because f
still refers to it even though the list doesn't. Of course, if f
is a local variable in a method, then as soon as the method returns, f
goes out of scope — at which point, if nothing else has a reference to the object, it's eligible for GC. But that's beside the point, the point is that when the clear
completes, the object is still referenced (by f
).