As we know java has automatic memory management by the process name called garbage collector. the JVM will call this GC for releasing the memory of the objects thats has no more references. as we know objects are eligable for garbage collection by Nulling a Reference,Reassigning a Reference Variable and Isolating a Reference. So in my example
in this code the reference variable myRef is pointing to myclassObject as the main method runs out of its scope does the JVM make myRef eligable for GC. suppose i mage a change
when could my reference variable myRef is eligable for GC ?
Now when line #10 is executed, then this is the object representation in the heap
So now in this object of myclass, the ref points to itself. So basically myRef in main method and myRef.ref point to the same object. Now when we set myRef to null, it no longer points to this object. And myRef.ref also cannot be accessed as myRef now points to null. So basically you cannot access this object.