Your logs show an OutOfMemoryError. How would you investigate it?

When an OutOfMemoryError occurs, it indicates that the JVM cannot allocate enough memory for new objects. The investigation should focus on identifying whether the issue is caused by a memory leak, insufficient heap allocation, excessive object creation, large data structures, or improper resource management.

Key Points

Example

Suppose an application stores user session data in a HashMap but never removes expired sessions. Over time, the map continues to grow, consuming heap memory until the JVM eventually throws an OutOfMemoryError. A heap dump analysis would reveal the large collection retaining most of the memory.

Interview Tip

A concise interview answer is: To investigate an OutOfMemoryError, I first identify the type of memory issue, review JVM heap settings, collect heap dumps, and analyze them using tools like Eclipse MAT or VisualVM. I then look for memory leaks, large collections, excessive object retention, and recent code changes. Finally, I validate the fix through monitoring and load testing to ensure the issue does not recur.

Last updated: 11 November 2026

Previous question: What happens if a final field is changed using reflection?

Next question: What does the Enum<?> type mean in Java?

More Core Java - Level IV (Advanced) interview questions

All Core Java - Level IV (Advanced) questions