From what I understand , if Object A has a reference to Object B as its instance variable , then the reference is stored within the space allocated for Object A on the heap. But Object B itself is stored somewhere else on the heap , outside of space allocated for Object A.
Is this understanding accurate ? What are the advantages of doing memory allocation this way (as opposed to having Object B within Object A on the heap) ?
What are the impacts of this (positive or negative) on the performance of Java's garbage collection mechanism (i.e if Object A get destroyed)?