From 28e4c9848fad5edb3fb31422be84da358b949fe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Wei=C3=9F?= Date: Sun, 6 Aug 2017 16:27:16 +0200 Subject: [PATCH] Removed call to Runtime.getRuntime().gc() every 10 frames, added call to Reference.clear() when an object is explicitly deleted. --- .../com/jme3/opencl/OpenCLObjectManager.java | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/opencl/OpenCLObjectManager.java b/jme3-core/src/main/java/com/jme3/opencl/OpenCLObjectManager.java index 4b761da5b..ec8276db3 100644 --- a/jme3-core/src/main/java/com/jme3/opencl/OpenCLObjectManager.java +++ b/jme3-core/src/main/java/com/jme3/opencl/OpenCLObjectManager.java @@ -45,10 +45,6 @@ public class OpenCLObjectManager { private static final Logger LOG = Logger.getLogger(OpenCLObjectManager.class.getName()); private static final Level LOG_LEVEL1 = Level.FINER; private static final Level LOG_LEVEL2 = Level.FINE; - /** - * Call Runtime.getRuntime().gc() every these frames - */ - private static final int GC_FREQUENCY = 10; private static final OpenCLObjectManager INSTANCE = new OpenCLObjectManager(); private OpenCLObjectManager() {} @@ -59,7 +55,6 @@ public class OpenCLObjectManager { private ReferenceQueue refQueue = new ReferenceQueue(); private HashSet activeObjects = new HashSet(); - private int gcCounter = 0; private static class OpenCLObjectRef extends PhantomReference { @@ -80,6 +75,7 @@ public class OpenCLObjectManager { private void deleteObject(OpenCLObjectRef ref) { LOG.log(LOG_LEVEL1, "deleting OpenCL object by: {0}", ref.releaser); ref.releaser.release(); + ref.clear(); activeObjects.remove(ref); } @@ -89,15 +85,6 @@ public class OpenCLObjectManager { return; //nothing to do } - gcCounter++; - if (gcCounter >= GC_FREQUENCY) { - //The program is that the OpenCLObjects are so small that they are - //enqueued for finalization very late. Therefore, without this - //hack, we are running out of host memory on the OpenCL side quickly. - gcCounter = 0; - Runtime.getRuntime().gc(); - } - int removed = 0; while (true) { // Remove objects reclaimed by GC. @@ -117,6 +104,7 @@ public class OpenCLObjectManager { for (OpenCLObjectRef ref : activeObjects) { LOG.log(LOG_LEVEL1, "deleting OpenCL object by: {0}", ref.releaser); ref.releaser.release(); + ref.clear(); } activeObjects.clear(); }