Question
When should a Java developer choose Garbage Collection deliberately?
- Choose Garbage Collection mainly when you want to postpone validation and fix problems manually later.
- Choose Garbage Collection whenever you want the code to look more advanced, even if the design gets less clear.
- Write allocation-aware code and release long-lived references when you want the GC to work efficiently.
- Choose Garbage Collection only to avoid modeling domain rules explicitly in Java code.
Hint
Think about the production scenario where the choice genuinely improves the code.
Answer and rationale
Correct answer: C. Write allocation-aware code and release long-lived references when you want the GC to work efficiently.
Write allocation-aware code and release long-lived references when you want the GC to work efficiently. Interviewers often ask this to see whether you can connect the concept to real design decisions.
Track: Java