diff --git a/source/org/jivesoftware/smackx/muc/MultiUserChat.java b/source/org/jivesoftware/smackx/muc/MultiUserChat.java index 4800011fd..d657ee711 100644 --- a/source/org/jivesoftware/smackx/muc/MultiUserChat.java +++ b/source/org/jivesoftware/smackx/muc/MultiUserChat.java @@ -2573,9 +2573,15 @@ public class MultiUserChat { private static class InvitationsMonitor implements ConnectionListener { // We use a WeakHashMap so that the GC can collect the monitor when the // connection is no longer referenced by any object. + // Note that when the InvitationsMonitor is used, i.e. when there are InvitationListeners, it will add a + // PacketListener to the Connection and therefore a strong reference from the Connection to the + // InvitationsMonior will exists, preventing it from beeing gc'ed. After the last InvitationListener is gone, + // the PacketListener will get removed (cancel()) allowing the garbage collection of the InvitationsMonitor + // instance. private final static Map> monitors = new WeakHashMap>(); + // We don't use a synchronized List here because it would break the semantic of (add|remove)InvitationListener private final List invitationsListeners = new ArrayList(); private Connection connection;