← 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?
- A.Creating many short-lived Strings inside a loop
- B.Using local variables in a method
- C.Adding every request's data to a static List and never removing it
- 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 →