From 4b893907f6d69ff28d57a27b4e986250303b790a Mon Sep 17 00:00:00 2001 From: Warrior <50800980+Warriorrrr@users.noreply.github.com> Date: Fri, 27 Dec 2024 23:25:02 +0100 Subject: [PATCH] Fix contextual map renderer memory leak (#11841) --- .../java/org/bukkit/craftbukkit/map/CraftMapView.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapView.java b/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapView.java index a15cdf6457..26a402b12f 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapView.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/map/CraftMapView.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.WeakHashMap; import java.util.logging.Level; import net.minecraft.resources.ResourceKey; import net.minecraft.server.MinecraftServer; @@ -19,9 +20,9 @@ import org.bukkit.map.MapView; public final class CraftMapView implements MapView { - private final Map renderCache = new HashMap(); - private final List renderers = new ArrayList(); - private final Map> canvases = new HashMap>(); + private final Map renderCache = new WeakHashMap<>(); + private final List renderers = new ArrayList<>(); + private final Map> canvases = new HashMap<>(); protected final MapItemSavedData worldMap; public CraftMapView(MapItemSavedData worldMap) { @@ -99,7 +100,7 @@ public final class CraftMapView implements MapView { public void addRenderer(MapRenderer renderer) { if (!this.renderers.contains(renderer)) { this.renderers.add(renderer); - this.canvases.put(renderer, new HashMap()); + this.canvases.put(renderer, new WeakHashMap<>()); renderer.initialize(this); } }