Java 17 - implementing Memory Leak in Spring Boot Application with Caching
I'm refactoring my project and I just started working with I'm experiencing a memory leak in my Spring Boot application using Java 17, which employs Caffeine for caching... The application performs well under low load, but as the load increases, I notice a important rise in memory usage. After profiling the application with VisualVM, I see that the memory consumption does not drop even after cache eviction occurs. Here's a snippet of how I'm configuring the cache: ```java @Bean public Cache<String, MyObject> myCache() { return Caffeine.newBuilder() .maximumSize(1000) .expireAfterWrite(10, TimeUnit.MINUTES) .recordStats() .build(); } ``` I've verified that my objects stored in the cache are not being referenced elsewhere in the application. I've also tried adding logging in the `evict` method, but it appears that evictions are happening as expected. Despite this, the heap size keeps growing. I even set up JMX monitoring to track cache statistics and noticed that the hit rate is decent, but the eviction count doesn't seem to correlate with the increasing memory usage. Iām using Spring Boot 2.5.4, and I've ensured that all dependencies are up to date. I've tried increasing the maximum size of the cache to see if it affects the behavior, but the leak continues. Any thoughts on how to resolve this or what else I should investigate? Any common pitfalls I might be missing related to cache configurations and memory management would be greatly appreciated! This is part of a larger web app I'm building. Thanks in advance! Any suggestions would be helpful. This is part of a larger desktop app I'm building. I'd really appreciate any guidance on this. I recently upgraded to Java LTS.