Preguntas de entrevista para Software engineer compartidas por los candidatos
We have to classes: A and B. Class A has a property that refers to an instance of B and Class B has a property that refers to an instance of A. Is it correct? Does it have any problem? If so, how would you solve it?
From a modeling point of view, it can be correct. But this presents a cycle. The problem is that as an object of A has a reference to B and viceversa, the garbage collector can't free that memory so you are leaking memory. To solve this, you need to make one of those references weak. Think which is the owner of the live of that relation and you will see which one has to be strong and which one weak.