← Quiz: Memory and Smart Pointers: all 10 questions
Quiz: Memory and Smart Pointers · Question 8 of 10
Two objects hold sharedptrs to each other. What goes wrong?
Two objects hold shared_ptrs to each other. What goes wrong?
- A.They are deleted twice
- B.Their reference counts never reach zero, so neither is freed (a memory leak)
- C.The program does not compile
- D.The pointers become null
Answer & explanation
Correct answer: Their reference counts never reach zero, so neither is freed (a memory leak)
Make one side a weak_ptr, which observes without owning, to break the cycle.
Can you get the rest right without peeking?
Take the timed Quiz: Memory and Smart Pointers quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →