🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.They are deleted twice
  2. B.Their reference counts never reach zero, so neither is freed (a memory leak)
  3. C.The program does not compile
  4. 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 →