Q:

the work of the garbage collector in Java

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?

A:

First, your program variables are never "available for garbage collection". Only objects are collected by the GC and program variables are references to objects, not objects themselves. (The common terminology in referring to Java variables confuses this point.)
Second, none of the objects referenced by a1, a2, or mas are going to be GC'ed. This is despite the fact that a1 and a2 have been set to null. This is because references to those objects are still reachable through either list or mas. Why is the object referenced by a2 still reachable through mas even after calling clear()? Because you cannot change the value of the variable mas in main() by passing the variable to the method clear(). All you are doing in that method is changing the formal parameter (also named mas), which is a separate variable from the local variable in main(). Java is strictly pass by value. However, when it comes to objects, what's always being passed is a reference. 
In general, the rule is that objects are GC'ed only if the objects are unreachable from any program variable, either directly or indirectly.

