What objects are available for garbage collection at the time of the call System.gc()
and why?
public class GCTest {
static class A {
private String myName;
public A(String myName) {
this.myName = myName;
}
}
public static void main(String[] args) {
A a1 = new A("a1");
A a2 = new A("a2");
ArrayList list = new ArrayList();
list.add(a1);
A[] mas = new A[2];
mas[0] = a2;
a2 = a1;
clear(mas);
a1 = null;
a2 = null;
System.gc();
// some code
...
}
private static void clear(A[] mas) {
mas = null;
}
}
if object == null
it becomes a garbage or not?
I think a1
, a2
and mas
are available for garbage collection at the time of the call System.gc()
because it state null. or I'm wrong?