From a797dba5943fb8a046d9cabc87fd5dd0f2d4e1eb Mon Sep 17 00:00:00 2001 From: "Kristian S. Stangeland" Date: Thu, 20 Jun 2013 01:06:50 +0200 Subject: [PATCH] Fixed a memory leak on Spigot that would retain unloaded worlds. --- .../injector/spigot/SpigotPacketInjector.java | 76 +++++++++---------- 1 file changed, 38 insertions(+), 38 deletions(-) diff --git a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/spigot/SpigotPacketInjector.java b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/spigot/SpigotPacketInjector.java index 555a5304..070e3c14 100644 --- a/ProtocolLib/src/main/java/com/comphenix/protocol/injector/spigot/SpigotPacketInjector.java +++ b/ProtocolLib/src/main/java/com/comphenix/protocol/injector/spigot/SpigotPacketInjector.java @@ -5,7 +5,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.Collections; import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import org.bukkit.Bukkit; @@ -37,6 +36,7 @@ import com.comphenix.protocol.reflect.MethodInfo; import com.comphenix.protocol.reflect.fuzzy.FuzzyMethodContract; import com.comphenix.protocol.utility.MinecraftReflection; import com.google.common.collect.MapMaker; +import com.google.common.collect.Maps; /** * Offload all the work to Spigot, if possible. @@ -58,6 +58,42 @@ public class SpigotPacketInjector implements SpigotPacketListener { * The amount of ticks to wait before removing all traces of a player. */ private static final int CLEANUP_DELAY = 100; + + // The listener we will register on Spigot. + // Unfortunately, due to the use of PlayerConnection, INetworkManager and Packet, we're + // unable to reference it directly. But with CGLib, it shouldn't cost us much. + private Object dynamicListener; + + // Reference to ProtocolLib + private Plugin plugin; + + // Different sending filters + private IntegerSet queuedFilters; + private IntegerSet reveivedFilters; + + // NetworkManager to injector and player + private ConcurrentMap networkManagerInjector = Maps.newConcurrentMap(); + + // Player to injector + private ConcurrentMap playerInjector = Maps.newConcurrentMap(); + + // Responsible for informing the PL packet listeners + private ListenerInvoker invoker; + private ErrorReporter reporter; + private Server server; + private ClassLoader classLoader; + + /** + * Create a new spigot injector. + */ + public SpigotPacketInjector(ClassLoader classLoader, ErrorReporter reporter, ListenerInvoker invoker, Server server) { + this.classLoader = classLoader; + this.reporter = reporter; + this.invoker = invoker; + this.server = server; + this.queuedFilters = new IntegerSet(Packets.MAXIMUM_PACKET_ID + 1); + this.reveivedFilters = new IntegerSet(Packets.MAXIMUM_PACKET_ID + 1); + } /** * Retrieve the spigot packet listener class. @@ -107,42 +143,6 @@ public class SpigotPacketInjector implements SpigotPacketListener { return getSpigotListenerClass() != null; } - // The listener we will register on Spigot. - // Unfortunately, due to the use of PlayerConnection, INetworkManager and Packet, we're - // unable to reference it directly. But with CGLib, it shouldn't cost us much. - private Object dynamicListener; - - // Reference to ProtocolLib - private Plugin plugin; - - // Different sending filters - private IntegerSet queuedFilters; - private IntegerSet reveivedFilters; - - // NetworkManager to injector and player - private ConcurrentMap networkManagerInjector = new ConcurrentHashMap(); - - // Player to injector - private ConcurrentMap playerInjector = new ConcurrentHashMap(); - - // Responsible for informing the PL packet listeners - private ListenerInvoker invoker; - private ErrorReporter reporter; - private Server server; - private ClassLoader classLoader; - - /** - * Create a new spigot injector. - */ - public SpigotPacketInjector(ClassLoader classLoader, ErrorReporter reporter, ListenerInvoker invoker, Server server) { - this.classLoader = classLoader; - this.reporter = reporter; - this.invoker = invoker; - this.server = server; - this.queuedFilters = new IntegerSet(Packets.MAXIMUM_PACKET_ID + 1); - this.reveivedFilters = new IntegerSet(Packets.MAXIMUM_PACKET_ID + 1); - } - /** * Register the Spigot packet injector. * @param plugin - the parent plugin. @@ -455,7 +455,7 @@ public class SpigotPacketInjector implements SpigotPacketListener { // Clean up playerInjector.remove(injector.getPlayer()); playerInjector.remove(injector.getUpdatedPlayer()); - networkManagerInjector.remove(injector); + networkManagerInjector.remove(injector.getNetworkManager()); } }, CLEANUP_DELAY); }