Skip to content

Commit

Permalink
Fixes memory leak in InfinispanAsyncMultiMap
Browse files Browse the repository at this point in the history
Calling ClusterManager.getAsyncMultiMap multiple times can leak memory as the cache listener is still registered.

See vert-x3/issues#316
  • Loading branch information
tsegismont committed Jan 10, 2018
1 parent 01a5efc commit 819a274
Showing 1 changed file with 8 additions and 1 deletion.
Expand Up @@ -61,14 +61,16 @@ public class InfinispanAsyncMultiMap<K, V> implements AsyncMultiMap<K, V> {

private final VertxInternal vertx;
private final Cache<MultiMapKey, Object> cache;
private final EntryListener listener;
private final ConcurrentMap<K, ChoosableSet<V>> nearCache;
private final TaskQueue taskQueue;

public InfinispanAsyncMultiMap(Vertx vertx, Cache<MultiMapKey, Object> cache) {
this.vertx = (VertxInternal) vertx;
this.cache = cache;
nearCache = new ConcurrentHashMap<>();
cache.addListener(new EntryListener());
listener = new EntryListener();
cache.addListener(listener);
taskQueue = new TaskQueue();
}

Expand Down Expand Up @@ -182,6 +184,11 @@ public void removeAllMatching(Predicate<V> p, Handler<AsyncResult<Void>> complet

}

@Override
public void close() {
cache.removeListener(listener);
}

public void clearCache() {
nearCache.clear();
}
Expand Down

0 comments on commit 819a274

Please sign in to comment.