From 9390125d6c9e9866d82829ca4d3b77eb70161da0 Mon Sep 17 00:00:00 2001 From: "Sha..rd" Date: Sun, 15 Apr 2012 19:38:39 +0000 Subject: [PATCH] * NativeObjectManager is now limited for 100 objects deleted per frame to reduce spikes with large heap config git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9319 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/util/NativeObjectManager.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/engine/src/core/com/jme3/util/NativeObjectManager.java b/engine/src/core/com/jme3/util/NativeObjectManager.java index f8d1d181d..3daf71ca0 100644 --- a/engine/src/core/com/jme3/util/NativeObjectManager.java +++ b/engine/src/core/com/jme3/util/NativeObjectManager.java @@ -51,6 +51,12 @@ public class NativeObjectManager { private static final Logger logger = Logger.getLogger(NativeObjectManager.class.getName()); + /** + * The maximum number of objects that should be removed per frame. + * If the limit is reached, no more objects will be removed for that frame. + */ + private static final int MAX_REMOVES_PER_FRAME = 100; + /** * The queue will receive notifications of {@link NativeObject}s which are no longer * referenced. @@ -91,15 +97,19 @@ public class NativeObjectManager { * Deletes unused GLObjects */ public void deleteUnused(Object rendererObject){ - while (true){ + int removed = 0; + while (removed < MAX_REMOVES_PER_FRAME) { NativeObjectRef ref = (NativeObjectRef) refQueue.poll(); if (ref == null) - return; + break; refList.remove(ref); ref.objClone.deleteObject(rendererObject); - if (logger.isLoggable(Level.FINEST)) - logger.log(Level.FINEST, "Deleted: {0}", ref.objClone); + removed++; + } + if (removed >= 1) { + //System.out.println("NativeObjectManager: " + removed + " native objects were removed from GL"); + logger.log(Level.FINE, "NativeObjectManager: {0} native objects were removed from GL", removed); } }