Skip to content

Commit

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

See vert-x3/issues#316
  • Loading branch information
tsegismont committed Jan 10, 2018
1 parent 2e09a0d commit 4afd815
Showing 1 changed file with 7 additions and 1 deletion.
Expand Up @@ -44,6 +44,7 @@ public class HazelcastAsyncMultiMap<K, V> implements AsyncMultiMap<K, V>, EntryL

private final VertxInternal vertx;
private final com.hazelcast.core.MultiMap<K, V> map;
private final String listenerRegistrationId;
private final TaskQueue taskQueue = new TaskQueue();


Expand All @@ -62,7 +63,7 @@ public class HazelcastAsyncMultiMap<K, V> implements AsyncMultiMap<K, V>, EntryL
public HazelcastAsyncMultiMap(Vertx vertx, com.hazelcast.core.MultiMap<K, V> map) {
this.vertx = (VertxInternal) vertx;
this.map = map;
map.addEntryListener(this, true);
listenerRegistrationId = map.addEntryListener(this, true);
}

@Override
Expand All @@ -83,6 +84,11 @@ public void removeAllMatching(Predicate<V> p, Handler<AsyncResult<Void>> complet
}, taskQueue, completionHandler);
}

@Override
public void close() {
map.removeEntryListener(listenerRegistrationId);
}

@Override
public void add(K k, V v, Handler<AsyncResult<Void>> completionHandler) {
vertx.getOrCreateContext().executeBlocking(fut -> {
Expand Down

0 comments on commit 4afd815

Please sign in to comment.