This repository is the result of preparation for internal talk in Intrum Global Technologies to share my knowledge about how the memory leaks are working, what the usual cases for them and how to spot & fix them.
- What's a memory leak?
- Java GC under the hood
- Passing object by reference
- The common leak cases
- Overload buffers - Zoe DEMO
- Unclosed connections / buffers
- Hidden infinite cycle - Bart DEMO
- Anonymous class context memory leak - Evelyn DEMO
- Tools to debug
- Visual VM
- Eclipse Memory Analyzer
- Questions
- Check amount of free memory after GC right after app startup and some time after
- Try to get HEAP dump and analyze it
- Try to figure out what is allocated in memory for your application
- Remember that memory leak not always looks like a memory leak, but usually as an overload CPU (because of infinite GC)
java \
-verbose:gc \
-Xmx25M \
-Dcom.sun.management.jmxremote \
-Dcom.sun.management.jmxremote.port=9010 \
-Dcom.sun.management.jmxremote.local.only=false \
-Dcom.sun.management.jmxremote.authenticate=false \
-Dcom.sun.management.jmxremote.ssl=false \
memory.MemoryEaterBart
- Visual VM - https://visualvm.github.io/
- Eclipse Memory Analyzer - https://www.eclipse.org/mat/
- Other tools listed here - https://stackify.com/java-memory-leaks-solutions/