Prevent memory leaks with loads of PacketMarker objects (#1511)

closes #1509
This commit is contained in:
Pasqual Koschmieder 2022-02-24 22:41:43 +01:00 committed by GitHub
parent 1b4d79b302
commit 151d4a289f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -275,7 +275,7 @@ public class ChannelInjector extends ByteToMessageDecoder implements Injector {
@Override @Override
public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception { public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
super.write(ctx, packet, promise); super.write(ctx, packet, promise);
ChannelInjector.this.finalWrite(); ChannelInjector.this.finalWrite(packet);
} }
@Override @Override
@ -544,7 +544,7 @@ public class ChannelInjector extends ByteToMessageDecoder implements Injector {
/** /**
* Invoked when a packet has been written to the channel * Invoked when a packet has been written to the channel
*/ */
private void finalWrite() { private void finalWrite(Object packet) {
PacketEvent event = finalEvent; PacketEvent event = finalEvent;
if (event != null) { if (event != null) {
@ -553,6 +553,10 @@ public class ChannelInjector extends ByteToMessageDecoder implements Injector {
currentEvent = null; currentEvent = null;
processor.invokePostEvent(event, NetworkMarker.getNetworkMarker(event)); processor.invokePostEvent(event, NetworkMarker.getNetworkMarker(event));
// remove the stored packet markers to prevent memory leaks
// See: https://github.com/dmulloy2/ProtocolLib/issues/1509
packetMarker.remove(packet);
} }
} }