Class B contains a reference to class A. since a reference IS the object
itself, I dont understand how come A is not destroyed when B is
destroyed - unless some kind of "reference counting" is employed "under
the hood" ?. BTW this is the desired behaviour - I just dont understand
how or why it works though ... and am seeking more of an insight to
explain this (maybe someone has a copy of the language reference)?
A reference is a permanent alias, its not the target object itself.
An object's lifetime is governed by the scope its in. Regardless of
whether a pointer of reference is targetting it.
Many will argue that a reference is an independant object altogether,
except that it happens to share its target's interface (public member
functions), returns its taget's address but it lives in its own
world / dimension / scope.
It doesn't make sense to have one object and 20 references to it and
then claim that you have 21 objects.
If your name is Bartholomy and you have a reference/alias of Bart -
thats still the same person.
If i chose to remove Bart from my list of friends - that doesn't
delete you. I'ld have to delete Bartholomy to do that.
If i slap Bart accross the face, only one person got slapped -
Bartholomy.