From 7aa91ca6353b66942f62309776c30fadc68823f3 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 23 Apr 2013 07:51:07 -0400 Subject: [PATCH] Try and be less noisy about world leaks --- .../common/DimensionManager.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/common/net/minecraftforge/common/DimensionManager.java b/common/net/minecraftforge/common/DimensionManager.java index 4035453cd..cadc9b27b 100644 --- a/common/net/minecraftforge/common/DimensionManager.java +++ b/common/net/minecraftforge/common/DimensionManager.java @@ -15,11 +15,13 @@ import java.util.concurrent.ConcurrentMap; import java.util.logging.Level; import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.HashMultiset; import com.google.common.collect.ImmutableListMultimap; import com.google.common.collect.ListMultimap; import com.google.common.collect.Lists; import com.google.common.collect.MapMaker; import com.google.common.collect.Maps; +import com.google.common.collect.Multiset; import com.google.common.collect.Sets; import cpw.mods.fml.common.FMLCommonHandler; @@ -52,7 +54,7 @@ public class DimensionManager private static ArrayList unloadQueue = new ArrayList(); private static BitSet dimensionMap = new BitSet(Long.SIZE << 4); private static ConcurrentMap weakWorldMap = new MapMaker().weakKeys().weakValues().makeMap(); - private static Set leakedWorlds = Sets.newHashSet(); + private static Multiset leakedWorlds = HashMultiset.create(); public static boolean registerProviderType(int id, Class provider, boolean keepLoaded) { @@ -163,23 +165,21 @@ public class DimensionManager { List allWorlds = Lists.newArrayList(weakWorldMap.keySet()); allWorlds.removeAll(worlds.values()); - Set newLeaks = Sets.newHashSet(); for (ListIterator li = allWorlds.listIterator(); li.hasNext(); ) { World w = li.next(); - if (leakedWorlds.contains(System.identityHashCode(w))) - { - li.remove(); - } - newLeaks.add(System.identityHashCode(w)); + leakedWorlds.add(System.identityHashCode(w)); } - leakedWorlds = newLeaks; - if (allWorlds.size() > 0) + for (World w : allWorlds) { - FMLLog.severe("Detected leaking worlds in memory. There are %d worlds that appear to be persisting. A mod is likely caching the world incorrectly\n", allWorlds.size() + leakedWorlds.size()); - for (World w : allWorlds) + int leakCount = leakedWorlds.count(System.identityHashCode(w)); + if (leakCount == 5) { - FMLLog.severe("The world %x (%s) has leaked.\n", System.identityHashCode(w), w.getWorldInfo().getWorldName()); + FMLLog.fine("The world %x (%s) may have leaked: first encounter (5 occurences).\n", System.identityHashCode(w), w.getWorldInfo().getWorldName()); + } + else if (leakCount % 5 == 0) + { + FMLLog.fine("The world %x (%s) may have leaked: seen %d times.\n", System.identityHashCode(w), w.getWorldInfo().getWorldName(), leakCount); } } }