🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Observer, Strategy and Decorator: all 10 questions

Quiz: Observer, Strategy and Decorator · Question 9 of 10

What is a common bug when using the Observer pattern in long-running apps?

What is a common bug when using the Observer pattern in long-running apps?

  1. A.Observers run before the subject is created
  2. B.The subject cannot have more than one observer
  3. C.Observers that are never unsubscribed stay in the list and cannot be garbage collected
  4. D.Lambdas cannot be used as observers
Answer & explanation

Correct answer: Observers that are never unsubscribed stay in the list and cannot be garbage collected

The subject's list keeps a reference, so forgotten observers leak memory.

Can you get the rest right without peeking?

Take the timed Quiz: Observer, Strategy and Decorator quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →