Search code examples
javamemory-leaksproduction-environment

Memory Leak detection in production code


I had a tough question during an interview today. They asked me how do I find the root cause of an out of memory error in my production code. I started talking about profilers. The interviewer pulled it to a different direction by saying how do I generate the traffic that's happening in production in order to benefit from the profiler. I didn't have a clue. Any information will be very helpful.


Solution

  • Profilers are not the best tool to chase memory leaks in production

    1. profilers are not run on production JVMs
    2. it is often impossible to recreate in dev or test the conditions that created the memory leak in production (the interviewer hint)

    The solution is to take a heap dump (using jmap for instance - JVM dependent) and analyze it using a tool like the excellent (and freely available) SAP Memory Analyzer (MAT)