mirror of
https://github.com/vanitasvitae/Smack.git
synced 2024-11-25 21:42:07 +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:
parent
f579fb2c77
commit
e0bc1ccaf2
1 changed files with 4 additions and 4 deletions
|
@ -22,6 +22,7 @@ import java.util.Collection;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.jivesoftware.smack.Manager;
|
||||||
import org.jivesoftware.smack.SmackException.NoResponseException;
|
import org.jivesoftware.smack.SmackException.NoResponseException;
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
import org.jivesoftware.smack.XMPPConnection;
|
||||||
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
import org.jivesoftware.smack.SmackException.NotConnectedException;
|
||||||
|
@ -36,7 +37,7 @@ import org.jivesoftware.smack.roster.packet.RosterPacket;
|
||||||
*
|
*
|
||||||
* @author Matt Tucker
|
* @author Matt Tucker
|
||||||
*/
|
*/
|
||||||
public class RosterEntry {
|
public final class RosterEntry extends Manager {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The JID of the entity/user.
|
* The JID of the entity/user.
|
||||||
|
@ -47,7 +48,6 @@ public class RosterEntry {
|
||||||
private RosterPacket.ItemType type;
|
private RosterPacket.ItemType type;
|
||||||
private RosterPacket.ItemStatus status;
|
private RosterPacket.ItemStatus status;
|
||||||
final private Roster roster;
|
final private Roster roster;
|
||||||
final private XMPPConnection connection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new roster entry.
|
* Creates a new roster entry.
|
||||||
|
@ -60,12 +60,12 @@ public class RosterEntry {
|
||||||
*/
|
*/
|
||||||
RosterEntry(String user, String name, RosterPacket.ItemType type,
|
RosterEntry(String user, String name, RosterPacket.ItemType type,
|
||||||
RosterPacket.ItemStatus status, Roster roster, XMPPConnection connection) {
|
RosterPacket.ItemStatus status, Roster roster, XMPPConnection connection) {
|
||||||
|
super(connection);
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.status = status;
|
this.status = status;
|
||||||
this.roster = roster;
|
this.roster = roster;
|
||||||
this.connection = connection;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,7 +103,7 @@ public class RosterEntry {
|
||||||
RosterPacket packet = new RosterPacket();
|
RosterPacket packet = new RosterPacket();
|
||||||
packet.setType(IQ.Type.set);
|
packet.setType(IQ.Type.set);
|
||||||
packet.addRosterItem(toRosterItem(this));
|
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
|
// We have received a result response to the IQ set, the name was successfully changed
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
Loading…
Reference in a new issue