You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by jw...@apache.org on 2016/10/12 02:50:03 UTC
groovy git commit: GROOVY-7646: allow classes to be removed from the
ClassInfo cache (closes #444)
Repository: groovy
Updated Branches:
refs/heads/GROOVY_2_4_X 4eadbde40 -> ca0e98d95
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/ca0e98d9
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/ca0e98d9
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/ca0e98d9
Branch: refs/heads/GROOVY_2_4_X
Commit: ca0e98d956dc0d99bcc7a35944f51c074652f0a2
Parents: 4eadbde
Author: Jochen Kemnade <jo...@eddyson.de>
Authored: Mon Oct 10 11:15:55 2016 +0200
Committer: John Wagenleitner <jw...@apache.org>
Committed: Tue Oct 11 19:45:55 2016 -0700
----------------------------------------------------------------------
.../org/codehaus/groovy/reflection/ClassInfo.java | 16 ++++++++++++++++
.../org/codehaus/groovy/runtime/InvokerHelper.java | 1 +
2 files changed, 17 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/ca0e98d9/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 542c8e4..72bc533 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/ca0e98d9/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 bf8bbc1..144662e 100644
--- a/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
+++ b/src/main/org/codehaus/groovy/runtime/InvokerHelper.java
@@ -66,6 +66,7 @@ public class InvokerHelper {
public static void removeClass(Class clazz) {
metaRegistry.removeMetaClass(clazz);
+ ClassInfo.remove(clazz);
Introspector.flushFromCaches(clazz);
}