There are different ways of dealing with Memory Issues. In this blog, I would like to share some steps you can take in order to find what could be causing memory leak.

It is always recommended to profile and test your application before deploying it to a Production environment. Using jVisualVM is a great way to quickly check the performance of your application.

This would be a good starting point: jVisualVM

The general symptoms when the memory usage high includes:

  • The application slow down overall
  • You would see higher rate of major/minor garbage collection
  • The Eden space usage would change very frequently

Using JCMD - A Swiss-army knife for investigating and resolving issues with your JVM application

This is a a great way to quickly check the details of the JVM, while it is running.

Here are some useful command and flags which you can use:

Get PID of all the Java Processes: jcmd

Collect Thread dump: jcmd PID Thread.print

JVM command line arguments: jcmd PID VM.command_line

Collect Heap Dump: jcmd PID GC.heap_dump /home/dump

Get Heap Memory Information: jcmd PID GC.heap_info


Best Practices and Recommendations

Enable Garbage Collection Logs:
You can add the following Application Setting for your WebApp to configure GC logs:
JAVA_OPTS=-Xloggc:/home/gc.log

Collect Heap Dump automatically on OutOfMemoryException:
-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/home/heapdump/

Integrate your application with Application Insights:
You can use the Application Insights codeless agent to integrate your application with AI. This does not need any code changes: Codeless Agent

Use Java Flight Recorder:
The recoding can be collected in two way - Timed and Continuous. Continuous recording is helpful when dealing with intermittent issues: JFR


Using Eclipse Memory Analyzer Tool: MAT
Zulu Mission Control: User Guide
Application Insights: Performance Counters
Analyze memory dump using jhat: Documentation