From 15a1d4cf0d9c906652c74d19c1653db395253df0 Mon Sep 17 00:00:00 2001 From: Lex Manos Date: Mon, 8 Jun 2015 16:19:53 -0700 Subject: [PATCH] Remove worlds from WorldBorder when unloaded tol prevent memory leak, Closes #1923 --- .../world/WorldServerMulti.java.patch | 38 ++++++++++++++++++- .../world/border/WorldBorder.java.patch | 12 ++++++ 2 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 patches/minecraft/net/minecraft/world/border/WorldBorder.java.patch diff --git a/patches/minecraft/net/minecraft/world/WorldServerMulti.java.patch b/patches/minecraft/net/minecraft/world/WorldServerMulti.java.patch index 65af8cdb3..8295a73c4 100644 --- a/patches/minecraft/net/minecraft/world/WorldServerMulti.java.patch +++ b/patches/minecraft/net/minecraft/world/WorldServerMulti.java.patch @@ -1,7 +1,28 @@ --- ../src-base/minecraft/net/minecraft/world/WorldServerMulti.java +++ ../src-work/minecraft/net/minecraft/world/WorldServerMulti.java -@@ -51,19 +51,22 @@ - }); +@@ -11,13 +11,14 @@ + public class WorldServerMulti extends WorldServer + { + private WorldServer field_175743_a; ++ private IBorderListener borderListener; + private static final String __OBFID = "CL_00001430"; + + public WorldServerMulti(MinecraftServer p_i45923_1_, ISaveHandler p_i45923_2_, int p_i45923_3_, WorldServer p_i45923_4_, Profiler p_i45923_5_) + { + super(p_i45923_1_, p_i45923_2_, new DerivedWorldInfo(p_i45923_4_.func_72912_H()), p_i45923_3_, p_i45923_5_); + this.field_175743_a = p_i45923_4_; +- p_i45923_4_.func_175723_af().func_177737_a(new IBorderListener() ++ this.borderListener = new IBorderListener() + { + private static final String __OBFID = "CL_00002273"; + public void func_177694_a(WorldBorder p_177694_1_, double p_177694_2_) +@@ -48,22 +49,26 @@ + { + WorldServerMulti.this.func_175723_af().func_177724_b(p_177695_2_); + } +- }); ++ }; ++ this.field_175743_a.func_175723_af().func_177737_a(this.borderListener); } - protected void func_73042_a() throws MinecraftException {} @@ -26,3 +47,16 @@ } else { +@@ -73,4 +78,12 @@ + + return this; + } ++ ++ ++ @Override ++ public void func_73041_k() ++ { ++ super.func_73041_k(); ++ this.field_175743_a.func_175723_af().removeListener(this.borderListener); // Unlink ourselves, to prevent world leak. ++ } + } diff --git a/patches/minecraft/net/minecraft/world/border/WorldBorder.java.patch b/patches/minecraft/net/minecraft/world/border/WorldBorder.java.patch new file mode 100644 index 000000000..c7f2cf0b9 --- /dev/null +++ b/patches/minecraft/net/minecraft/world/border/WorldBorder.java.patch @@ -0,0 +1,12 @@ +--- ../src-base/minecraft/net/minecraft/world/border/WorldBorder.java ++++ ../src-work/minecraft/net/minecraft/world/border/WorldBorder.java +@@ -293,4 +293,9 @@ + iborderlistener.func_177690_b(this, p_177747_1_); + } + } ++ ++ public void removeListener(IBorderListener listener) ++ { ++ this.field_177758_a.remove(listener); ++ } + }