From 7ea2f54286f1ef280e09d24066828dd803d1d11d Mon Sep 17 00:00:00 2001 From: "PSp..om" Date: Fri, 22 Jul 2011 09:12:11 +0000 Subject: [PATCH] Turning the memory tracking off since it's pretty expensive and broken anyway. See comment in source. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7899 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../src/core/com/jme3/util/BufferUtils.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/engine/src/core/com/jme3/util/BufferUtils.java b/engine/src/core/com/jme3/util/BufferUtils.java index ce6f298dd..4c534226f 100644 --- a/engine/src/core/com/jme3/util/BufferUtils.java +++ b/engine/src/core/com/jme3/util/BufferUtils.java @@ -58,7 +58,26 @@ public final class BufferUtils { private static final Map trackingHash = Collections.synchronizedMap(new WeakHashMap()); private static final Object ref = new Object(); - private static final boolean trackDirectMemory = true; + + // Note: a WeakHashMap is really bad here since the hashCode() and + // equals() behavior of buffers will vary based on their contents. + // As it stands, put()'ing an empty buffer will wipe out the last + // empty buffer with the same size. So any tracked memory calculations + // could be lying. + // Besides, the hashmap behavior isn't even being used here and + // yet the expense is still incurred. For example, a newly allocated + // 10,000 byte buffer will iterate through the whole buffer of 0's + // to calculate the hashCode and then potentially do it again to + // calculate the equals()... which by the way is guaranteed for + // every empty buffer of an existing size since they will always produce + // the same hashCode(). + // It would be better to just keep a straight list of weak references + // and clean out the dead every time a new buffer is allocated. + // WeakHashMap is doing that anyway... to there is no extra expense + // incurred. + // Recommend a ConcurrentLinkedQueue of WeakReferences since it + // supports the threading semantics required with little extra overhead. + private static final boolean trackDirectMemory = false; /** * Creates a clone of the given buffer. The clone's capacity is