Your Spring Boot app is using 2GB of memory. It was 512MB last week.
No errors. App still responds. Just slower every day.
Then one morning: OutOfMemoryError. App is dead. You restart it. Next week, same thing.
That's a memory leak. And restarting is not a fix.
Something in your code is holding references to objects that should have been garbage collected. Heap keeps growing. GC runs but can't free anything. Eventually no space left.
Common culprits in Spring Boot:
→ JPA Stream<Entity> not closed — EntityManager holds every entity in memory. 100K rows loaded, none released.
→ ThreadLocal not cleared after request — filter stores user context, request ends, ThreadLocal stays. Memory piles up with every request.
→ ConcurrentHashMap as cache without eviction — data goes in, nothing comes out. No TTL. No max size. Grows until heap explodes.
→ Static List or Map that only grows — .add() on every request, never .clear(). Classic leak.
How to find it:
→ Monitor /actuator/metrics/jvm.memory.used — if heap grows and never drops after GC, you have a leak
→ Take heap dump before the crash: jmap -dump:format=b,file=heap.hprof <pid>
→ Open in Eclipse MAT → run Leak Suspects Report → it tells you exactly which object is eating memory
Memory leaks don't crash your app on day one. They crash it on the day your biggest client is using it.
#memoryleaks