1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2024-11-02 06:45:59 +01:00

Fix memory leak in RosterEntry

Roster's INSTANCE map has a weak reference to XMPPConnection, which has
a field of RosterEntry(ies), and RosterEntry has a strong reference to
XMPPConnection resulting in a cycle which is preventing XMPPConnection
from getting gc'ed.

SMACK-659.
This commit is contained in:
Florian Schmaus 2015-04-27 07:27:38 +02:00
parent f579fb2c77
commit e0bc1ccaf2

View file

@ -22,6 +22,7 @@ import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import org.jivesoftware.smack.Manager;
import org.jivesoftware.smack.SmackException.NoResponseException;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.SmackException.NotConnectedException;
@ -36,7 +37,7 @@ import org.jivesoftware.smack.roster.packet.RosterPacket;
*
* @author Matt Tucker
*/
public class RosterEntry {
public final class RosterEntry extends Manager {
/**
* The JID of the entity/user.
@ -47,7 +48,6 @@ public class RosterEntry {
private RosterPacket.ItemType type;
private RosterPacket.ItemStatus status;
final private Roster roster;
final private XMPPConnection connection;
/**
* Creates a new roster entry.
@ -60,12 +60,12 @@ public class RosterEntry {
*/
RosterEntry(String user, String name, RosterPacket.ItemType type,
RosterPacket.ItemStatus status, Roster roster, XMPPConnection connection) {
super(connection);
this.user = user;
this.name = name;
this.type = type;
this.status = status;
this.roster = roster;
this.connection = connection;
}
/**
@ -103,7 +103,7 @@ public class RosterEntry {
RosterPacket packet = new RosterPacket();
packet.setType(IQ.Type.set);
packet.addRosterItem(toRosterItem(this));
connection.createPacketCollectorAndSend(packet).nextResultOrThrow();
connection().createPacketCollectorAndSend(packet).nextResultOrThrow();
// We have received a result response to the IQ set, the name was successfully changed
this.name = name;