Pointers, links, object and reference count
- by EugeneP
String a = "a"; // allocate memory and write address of a memory block to a variable
String b = "b";
// in a and b hold addresses
b = a; // copy a address into b.
// Now what? b value is completely lost and will be garbage collected
//* next step
a = null; // now a does not hold a valid address to any data,
// still data of a object exist somewhere, yet we cannot get access to it.
Correct me if there's a mistake somewhere in my reflexions.
My question is:
suppose anInstance object of type Instance has a property ' surname '
anInstance.getSurname() returns "MySurname".
now String s = anInstance.getSurname();
anInstance = null;
question is - is it true that getSurname value, namely MySurname
will not be garbage collected because and only because
it has active reference
counter 0, and if other properties of anInstance
have a zero reference counter, they'll be
garbage collected?