Jesper de Jong wrote:
No, that is not possible. In your example, member variable 'b' is part of the object. You can't delete part of an object.
However, if b was a reference variable rather than a primitive, and if there are no other reachable references to the object that b points to, and if you set b to null, then the object that b pointed to becomes eligible for GC.
In other words, it doesn't matter how an object is referenced before becoming unreachable--member variable, local variable, or just as the result of an expression--all that matters is that a reachable object is not eligible for GC and an unreachable one is eligible.
Also note that we almost never explicitly set individual member variables to null in order to "help" the GC. We do sometimes remove objects from collections, or set an array reference to null, when the object is no longer needed. In general though, you don't need to, and should not try to, help the GC by setting references to null.