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

Quiz: JVM Memory and Garbage Collection · Question 9 of 10

Which code is most likely to cause a memory leak in a long-running server?

Which code is most likely to cause a memory leak in a long-running server?

  1. A.Creating many short-lived Strings inside a loop
  2. B.Using local variables in a method
  3. C.Adding every request's data to a static List and never removing it
  4. D.Two objects referring to each other
Answer & explanation

Correct answer: Adding every request's data to a static List and never removing it

Static fields are GC roots, so everything in the ever-growing list stays reachable and can never be collected.

Can you get the rest right without peeking?

Take the timed Quiz: JVM Memory and Garbage Collection quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →