1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-11-26 14:02:06 +01:00

SMACK-374 Added patch to fix memory leak.

git-svn-id: http://svn.igniterealtime.org/svn/repos/smack/trunk@13372 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
rcollier 2012-11-22 02:51:51 +00:00
parent 012e1252e2
commit 9cd16fe3dd

View file

@ -20,19 +20,25 @@
package org.jivesoftware.smackx; package org.jivesoftware.smackx;
import org.jivesoftware.smack.*; import java.lang.ref.WeakReference;
import org.jivesoftware.smack.util.collections.ReferenceMap; import java.util.Map;
import org.jivesoftware.smack.filter.PacketFilter; import java.util.WeakHashMap;
import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.ChatManagerListener;
import org.jivesoftware.smack.Connection;
import org.jivesoftware.smack.MessageListener;
import org.jivesoftware.smack.PacketInterceptor;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.NotFilter; import org.jivesoftware.smack.filter.NotFilter;
import org.jivesoftware.smack.filter.PacketExtensionFilter; import org.jivesoftware.smack.filter.PacketExtensionFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.Message; import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Packet; import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension; import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.util.collections.ReferenceMap;
import org.jivesoftware.smackx.packet.ChatStateExtension; import org.jivesoftware.smackx.packet.ChatStateExtension;
import java.util.Map;
import java.util.WeakHashMap;
/** /**
* Handles chat state for all chats on a particular Connection. This class manages both the * Handles chat state for all chats on a particular Connection. This class manages both the
* packet extensions and the disco response neccesary for compliance with * packet extensions and the disco response neccesary for compliance with
@ -48,8 +54,8 @@ import java.util.WeakHashMap;
*/ */
public class ChatStateManager { public class ChatStateManager {
private static final Map<Connection, ChatStateManager> managers = private static final Map<Connection, WeakReference<ChatStateManager>> managers =
new WeakHashMap<Connection, ChatStateManager>(); new WeakHashMap<Connection, WeakReference<ChatStateManager>>();
private static final PacketFilter filter = new NotFilter( private static final PacketFilter filter = new NotFilter(
new PacketExtensionFilter("http://jabber.org/protocol/chatstates")); new PacketExtensionFilter("http://jabber.org/protocol/chatstates"));
@ -66,12 +72,16 @@ public class ChatStateManager {
return null; return null;
} }
synchronized (managers) { synchronized (managers) {
ChatStateManager manager = managers.get(connection); ChatStateManager manager;
if (manager == null) { WeakReference<ChatStateManager> ref = managers.get(connection);
if (ref == null) {
manager = new ChatStateManager(connection); manager = new ChatStateManager(connection);
manager.init(); manager.init();
managers.put(connection, manager); managers.put(connection, new WeakReference<ChatStateManager>(manager));
} }
else
manager = ref.get();
return manager; return manager;
} }