From 2b76a5bc17814ce68f100728875f8143e2979b7c Mon Sep 17 00:00:00 2001 From: KennyTV Date: Sun, 9 Feb 2020 14:13:54 +0100 Subject: [PATCH] Resolve memory leak --- .../packets/BlockItemPackets1_13.java | 14 ++++++++++---- .../storage/BackwardsBlockStorage.java | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java index 71014d02..74c67d3c 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/packets/BlockItemPackets1_13.java @@ -181,10 +181,16 @@ public class BlockItemPackets1_13 extends nl.matsv.viabackwards.api.rewriters.It handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - /*int x = wrapper.passthrough(Type.INT); - int z = wrapper.passthrough(Type.INT; - BackwardsBlockStorage blockStorage = wrapper.user().get(BackwardsBlockStorage.class);*/ - //TODO UNCACHE BLOCKSTORAGE ENTRIES - MEMORY LEAK! + int chunkMinX = wrapper.passthrough(Type.INT) << 4; + int chunkMinZ = wrapper.passthrough(Type.INT) << 4; + int chunkMaxX = chunkMinX + 15; + int chunkMaxZ = chunkMinZ + 15; + BackwardsBlockStorage blockStorage = wrapper.user().get(BackwardsBlockStorage.class); + blockStorage.getBlocks().entrySet().removeIf(entry -> { + Position position = entry.getKey(); + return position.getX() >= chunkMinX && position.getZ() >= chunkMinZ + && position.getX() <= chunkMaxX && position.getZ() <= chunkMaxZ; + }); } }); } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java index 87260e9d..dfb707c8 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12_2to1_13/storage/BackwardsBlockStorage.java @@ -87,4 +87,8 @@ public class BackwardsBlockStorage extends StoredObject { public void clear() { blocks.clear(); } + + public Map getBlocks() { + return blocks; + } }