Middle
Have you ever had to deal with OOM (OutOfMemoryError)? How did you debug memory issues?
sobes.tech AI
Answer from AI
Yes, I have encountered OutOfMemoryError (OOM) in Java. To debug such issues, I usually follow this approach:
- Analyze the error log to understand when and in which thread the error occurred.
- Collect a heap dump using tools like jmap or JVM parameters.
- Analyze the heap dump with profilers such as VisualVM, Eclipse MAT, or YourKit to identify objects occupying a lot of memory.
- Search for memory leaks — for example, objects that are not released due to references.
- Optimize the code: fix leaks, reduce the size of cached data, use weak references.
- If necessary, configure JVM parameters (heap size, garbage collector).
Example command to create a heap dump on OOM:
java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/path/to/dump.hprof -jar app.jar