Two objects hold std::shared_ptr to each other. Why is neither destructor called when the last external owner releases them?
Correct answer
C. Each object's reference count stays at one because of the mutual strong references
14 views
C. Each object's reference count stays at one because of the mutual strong references
14 views
Reference counting cannot reclaim cycles: each object is still strongly owned by its partner, so both counts stay at least one and the destructors never run. Break the cycle with std::weak_ptr on one side, or restructure so only one direction is strong. This is the classic shared_ptr leak that memory checkers report as still reachable rather than definitely lost.
Asked in: NTS, PPSC IT, Campus Interviews
Not sure why the answer is C? Ask here and get an explanation.