Attempting to correct a memory leak in ticket #189.

This commit is contained in:
Kristian S. Stangeland 2014-01-13 03:46:06 +01:00
parent e23129540c
commit 0c718f9484
4 changed files with 11 additions and 10 deletions

View File

@ -921,8 +921,9 @@ public final class PacketFilterManager implements ProtocolManager, ListenerInvok
* @param players - list of players to uninject. * @param players - list of players to uninject.
*/ */
public void uninitializePlayers(Player[] players) { public void uninitializePlayers(Player[] players) {
for (Player player : players) for (Player player : players) {
playerInjection.uninjectPlayer(player); playerInjection.uninjectPlayer(player);
}
} }
/** /**

View File

@ -14,7 +14,6 @@ import com.comphenix.protocol.reflect.FuzzyReflection;
import com.comphenix.protocol.utility.MinecraftFields; import com.comphenix.protocol.utility.MinecraftFields;
import com.comphenix.protocol.utility.MinecraftReflection; import com.comphenix.protocol.utility.MinecraftReflection;
import com.google.common.collect.MapMaker; import com.google.common.collect.MapMaker;
import com.google.common.collect.Maps;
/** /**
* Represents an injector factory. * Represents an injector factory.
@ -23,11 +22,12 @@ import com.google.common.collect.Maps;
* @author Kristian * @author Kristian
*/ */
class InjectionFactory { class InjectionFactory {
private final ConcurrentMap<Player, Injector> playerLookup = Maps.newConcurrentMap(); // This should work as long as the injectors are, uh, injected
private final ConcurrentMap<Player, Injector> playerLookup = new MapMaker().weakKeys().weakValues().makeMap();
private final ConcurrentMap<String, Injector> nameLookup = new MapMaker().weakValues().makeMap(); private final ConcurrentMap<String, Injector> nameLookup = new MapMaker().weakValues().makeMap();
// Whether or not the factory is closed // Whether or not the factory is closed
private boolean closed; private volatile boolean closed;
/** /**
* Construct or retrieve a channel injector from an existing Bukkit player. * Construct or retrieve a channel injector from an existing Bukkit player.
@ -44,7 +44,7 @@ class InjectionFactory {
// Find a temporary injector as well // Find a temporary injector as well
if (injector == null) if (injector == null)
injector = getTemporaryInjector(player); injector = getTemporaryInjector(player);
if (injector != null) if (injector != null && !injector.isClosed())
return injector; return injector;
Object networkManager = MinecraftFields.getNetworkManager(player); Object networkManager = MinecraftFields.getNetworkManager(player);

View File

@ -328,10 +328,10 @@ public class NettyProtocolInjector implements ChannelListener {
@Override @Override
public boolean uninjectPlayer(Player player) { public boolean uninjectPlayer(Player player) {
injectionFactory.fromPlayer(player, listener).close(); // Just let Netty clean this up
return true; return true;
} }
@Override @Override
public void sendServerPacket(Player receiver, PacketContainer packet, NetworkMarker marker, boolean filters) throws InvocationTargetException { public void sendServerPacket(Player receiver, PacketContainer packet, NetworkMarker marker, boolean filters) throws InvocationTargetException {
injectionFactory.fromPlayer(receiver, listener). injectionFactory.fromPlayer(receiver, listener).

View File

@ -98,12 +98,12 @@ public interface PlayerInjectionHandler {
public abstract void handleDisconnect(Player player); public abstract void handleDisconnect(Player player);
/** /**
* Unregisters the given player. * Uninject the given player.
* @param player - player to unregister. * @param player - player to uninject.
* @return TRUE if a player has been uninjected, FALSE otherwise. * @return TRUE if a player has been uninjected, FALSE otherwise.
*/ */
public abstract boolean uninjectPlayer(Player player); public abstract boolean uninjectPlayer(Player player);
/** /**
* Unregisters a player by the given address. * Unregisters a player by the given address.
* <p> * <p>