-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Description
We faced a memory leak after upgrading caffeine from 2.2.7 to 2.3.1. It seems that cache entries are not evicted when using weak values. Following test is working on 2.2.7 but eats all memory with 2.3.1:
@Test
public void testWeakValuesEviction() throws InterruptedException {
Cache<Long, Object> cache = Caffeine.newBuilder().executor(e -> e.run()).weakValues().recordStats().build();
ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1);
AtomicLong versionCounter = new AtomicLong(1L);
exec.scheduleAtFixedRate(() -> {
int idCounter = 1;
while (idCounter++ < 200_000) {
cache.put(versionCounter.getAndIncrement(), new Object());
}
} , 0L, 500L, TimeUnit.MILLISECONDS);
for (;;) {
Thread.sleep(10000);
CacheStats stats = cache.stats();
System.out.println(stats.toString());
// cache.cleanUp();
System.gc();
}
}
Eviction count stays at zero on 2.3.1 while growing fast on 2.2.7. If cache is cleaned up explicitly from outside, entries are evicted.
Metadata
Metadata
Assignees
Labels
No labels