Resolve memory leak

This commit is contained in:
KennyTV 2020-02-09 14:13:54 +01:00
parent ba7333184b
commit 2b76a5bc17
2 changed files with 14 additions and 4 deletions

View File

@ -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;
});
}
});
}

View File

@ -87,4 +87,8 @@ public class BackwardsBlockStorage extends StoredObject {
public void clear() {
blocks.clear();
}
public Map<Position, Integer> getBlocks() {
return blocks;
}
}