groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jwagenleit...@apache.org
Subject [1/2] groovy git commit: GROOVY-7646: allow classes to be removed from the ClassInfo cache (closes #444)
Date Wed, 12 Oct 2016 03:14:39 GMT
Repository: groovy
Updated Branches:
  refs/heads/master 2706b53c3 -> 4ea1207f2


GROOVY-7646: allow classes to be removed from the ClassInfo cache (closes #444)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/d4eadc4c
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/d4eadc4c
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/d4eadc4c

Branch: refs/heads/master
Commit: d4eadc4cfe63f0d2a01ba872cc2abfdaaf1a8323
Parents: 2706b53
Author: Jochen Kemnade <jochen.kemnade@eddyson.de>
Authored: Mon Oct 10 11:15:55 2016 +0200
Committer: John Wagenleitner <jwagenleitner@apache.org>
Committed: Tue Oct 11 19:33:16 2016 -0700

----------------------------------------------------------------------
 .../org/codehaus/groovy/reflection/ClassInfo.java   | 16 ++++++++++++++++
 .../org/codehaus/groovy/runtime/InvokerHelper.java  |  2 ++
 2 files changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/d4eadc4c/src/main/org/codehaus/groovy/reflection/ClassInfo.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/reflection/ClassInfo.java b/src/main/org/codehaus/groovy/reflection/ClassInfo.java
index b5bf80e..57956af 100644
--- a/src/main/org/codehaus/groovy/reflection/ClassInfo.java
+++ b/src/main/org/codehaus/groovy/reflection/ClassInfo.java
@@ -144,6 +144,22 @@ public class ClassInfo implements Finalizable {
         return globalClassValue.get(cls);
     }
 
+    /**
+     * Removes a {@code ClassInfo} from the cache.
+     *
+     * This is useful in cases where the Class is parsed from a script, such as when
+     * using GroovyClassLoader#parseClass, and is executed for its result but the Class
+     * is not retained or cached.  Removing the {@code ClassInfo} associated with the Class
+     * will make the Class and its ClassLoader eligible for garbage collection sooner that
+     * it would otherwise.
+     *
+     * @param cls the Class associated with the ClassInfo to remove
+     *            from cache
+     */
+    public static void remove(Class<?> cls) {
+        globalClassValue.remove(cls);
+    }
+
     public static Collection<ClassInfo> getAllClassInfo () {
         return getAllGlobalClassInfo();
     }

http://git-wip-us.apache.org/repos/asf/groovy/blob/d4eadc4c/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/InvokerHelper.java b/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
index faa142c..6f7406a 100644
--- a/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
+++ b/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
@@ -36,6 +36,7 @@ import groovy.lang.SpreadMapEvaluatingException;
 import groovy.lang.Tuple;
 import groovy.lang.Writable;
 import org.codehaus.groovy.control.ResolveVisitor;
+import org.codehaus.groovy.reflection.ClassInfo;
 import org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl;
 import org.codehaus.groovy.runtime.metaclass.MissingMethodExecutionFailed;
 import org.codehaus.groovy.runtime.powerassert.PowerAssertionError;
@@ -86,6 +87,7 @@ public class InvokerHelper {
 
     public static void removeClass(Class clazz) {
         metaRegistry.removeMetaClass(clazz);
+        ClassInfo.remove(clazz);
         Introspector.flushFromCaches(clazz);
     }
 


Mime
View raw message