Fix server-side data not being released (#4882)

This commit is contained in:
Ben Staddon authored and LexManos committed 2018-05-16 23:13:27 -07:00
1 parent 8fdc6eff07
commit 330a9c4fd3
4 files changed
+45 -26

No files matched your search

@@ -28,6 +28,7 @@ import net.minecraft.network.Packet;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.ModContainer;
import net.minecraftforge.fml.common.network.FMLOutboundHandler.OutboundTarget;
import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher;
import net.minecraftforge.fml.common.network.internal.FMLProxyPacket;
import net.minecraftforge.fml.relauncher.Side;
@@ -88,4 +89,11 @@ public class FMLEmbeddedChannel extends EmbeddedChannel {
}
return targetName;
}
public void cleanAttributes()
{
this.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(null);
this.attr(NetworkRegistry.NET_HANDLER).set(null);
this.attr(NetworkDispatcher.FML_DISPATCHER).set(null);
}
}
@@ -27,12 +27,9 @@ import io.netty.util.AttributeKey;
import java.util.Collection;
import java.util.EnumMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
import org.apache.logging.log4j.Level;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
@@ -342,11 +339,16 @@ public enum NetworkRegistry
public void fireNetworkHandshake(NetworkDispatcher networkDispatcher, Side origin)
{
NetworkHandshakeEstablished handshake = new NetworkHandshakeEstablished(networkDispatcher, networkDispatcher.getNetHandler(), origin);
for (Entry<String, FMLEmbeddedChannel> channel : channels.get(origin).entrySet())
for (FMLEmbeddedChannel channel : channels.get(origin).values())
{
channel.getValue().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.DISPATCHER);
channel.getValue().attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(networkDispatcher);
channel.getValue().pipeline().fireUserEventTriggered(handshake);
channel.attr(FMLOutboundHandler.FML_MESSAGETARGET).set(OutboundTarget.DISPATCHER);
channel.attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(networkDispatcher);
channel.pipeline().fireUserEventTriggered(handshake);
}
}
public void cleanAttributes()
{
channels.values().forEach(map -> map.values().forEach(FMLEmbeddedChannel::cleanAttributes));
}
}
@@ -604,8 +604,8 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler<Packet<?>> im
super.exceptionCaught(ctx, cause);
}
// if we add any attributes, we should force removal of them here so that
//they do not hold references to the world and causes it to leak.
// If we add any attributes, we should force removal of them here so that
// they do not hold references to the world and cause it to leak.
private void cleanAttributes(ChannelHandlerContext ctx)
{
ctx.channel().attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(null);
@@ -613,6 +613,7 @@ public class NetworkDispatcher extends SimpleChannelInboundHandler<Packet<?>> im
ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).set(null);
this.handshakeChannel.attr(FML_DISPATCHER).set(null);
this.manager.channel().attr(FML_DISPATCHER).set(null);
NetworkRegistry.INSTANCE.cleanAttributes();
}
public void setOverrideDimension(int overrideDim) {