when something is set to null it is available for GC
Don't mean to be pedantic, but this is not always true.
Setting to null will make an object available for GC provided the object has no other references to it from live threads.
In the case of this example, prior to setting rg=null, the object created by "new Integer(3)" had 3 references pointing to it, namely
rg
dg[0][1]
dg[0][1]
Now when rg gets set to null, the object (new Integer(3)) still has 2 references pointing to it. So whilst still in the method, the object is not available for GC.
The object however does become available for GC after the method exists. This is because the dg array is local to the method. When the method exits, the dg references get removed from the stack and thus the object (new Integer(3)) has no live references anymore.
Note that if rg had not been set to null, the rg references would also have been removed when the method exits. However the object would not necessarily be available for GC because the reference was being passed back as a return object - which could be assigned to a live reference.