Sobes.tech
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:

  1. Analyze the error log to understand when and in which thread the error occurred.
  2. Collect a heap dump using tools like jmap or JVM parameters.
  3. Analyze the heap dump with profilers such as VisualVM, Eclipse MAT, or YourKit to identify objects occupying a lot of memory.
  4. Search for memory leaks — for example, objects that are not released due to references.
  5. Optimize the code: fix leaks, reduce the size of cached data, use weak references.
  6. 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