From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Spottedleaf Date: Mon, 13 Jul 2020 06:22:54 -0700 Subject: [PATCH] Fix AdvancementDataPlayer leak due from quitting early in login Move the criterion storage to the AdvancementDataPlayer object itself, so the criterion object stores no references - and thus needs no cleanup. diff --git a/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java b/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java index 31650e41b37e322d2e8a4d4a3deec95851e72675..a645c79af856d2484a4ce7aa2885a32358b9a480 100644 --- a/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java +++ b/src/main/java/net/minecraft/advancements/critereon/SimpleCriterionTrigger.java @@ -16,25 +16,25 @@ import net.minecraft.world.level.storage.loot.LootContext; public abstract class SimpleCriterionTrigger implements CriterionTrigger { - private final Map>> a = Maps.newIdentityHashMap(); + //private final Map>> a = Maps.newIdentityHashMap(); // Paper - moved into AdvancementDataPlayer to fix memory leak public SimpleCriterionTrigger() {} @Override public final void a(PlayerAdvancements advancementdataplayer, CriterionTrigger.Listener criteriontrigger_a) { - ((Set) this.a.computeIfAbsent(advancementdataplayer, (advancementdataplayer1) -> { + (advancementdataplayer.criterionData.computeIfAbsent(this, (advancementdataplayer1) -> { // Paper - fix AdvancementDataPlayer leak return Sets.newHashSet(); })).add(criteriontrigger_a); } @Override public final void b(PlayerAdvancements advancementdataplayer, CriterionTrigger.Listener criteriontrigger_a) { - Set> set = (Set) this.a.get(advancementdataplayer); + Set> set = (Set) advancementdataplayer.criterionData.get(this); // Paper - fix AdvancementDataPlayer leak if (set != null) { set.remove(criteriontrigger_a); if (set.isEmpty()) { - this.a.remove(advancementdataplayer); + advancementdataplayer.criterionData.remove(this); // Paper - fix AdvancementDataPlayer leak } } @@ -42,7 +42,7 @@ public abstract class SimpleCriterionTrigger tester) { PlayerAdvancements advancementdataplayer = player.getAdvancements(); - Set> set = (Set) this.a.get(advancementdataplayer); + Set> set = (Set) advancementdataplayer.criterionData.get(this); // Paper - fix AdvancementDataPlayer leak if (set != null && !set.isEmpty()) { LootContext loottableinfo = EntityPredicate.createContext(player, player); @@ -67,7 +67,7 @@ public abstract class SimpleCriterionTrigger> criterionData = Maps.newIdentityHashMap(); + // Paper end - fix advancement data player leakage + public PlayerAdvancements(DataFixer datafixer, PlayerList playerlist, ServerAdvancementManager advancementdataworld, File file, ServerPlayer entityplayer) { this.dataFixer = datafixer; this.playerList = playerlist;