From f61968f30255063c02971f041a0111e5dcf84220 Mon Sep 17 00:00:00 2001 From: "Kevin W. Sutter" Date: Wed, 1 Aug 2007 21:55:44 +0000 Subject: [PATCH] OPENJPA-285. I am going ahead with the integration of Kevan's patches for the two memory leaks found in OpenJPA while testing Geronimo. I will post more details in the Issue. git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@561970 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/openjpa/enhance/PCRegistry.java | 17 +++++++++++++++++ .../org/apache/openjpa/util/ImplHelper.java | 4 ++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java index 5703ed291..308669890 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCRegistry.java @@ -202,6 +202,23 @@ public class PCRegistry { } } + /** + * De-Register all metadata associated with the given ClassLoader. + * Allows ClassLoaders to be garbage collected. + * + * @param cl the ClassLoader + */ + public static void deRegister(ClassLoader cl) { + synchronized (_metas) { + for (Iterator i = _metas.keySet().iterator(); i.hasNext();) { + Class pcClass = (Class) i.next(); + if (pcClass.getClassLoader() == cl) { + _metas.remove(pcClass); + } + } + } + } + /** * Returns a collection of class objects of the registered * persistence-capable classes. diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java b/openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java index bf502e30a..067ed5c30 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/util/ImplHelper.java @@ -39,7 +39,6 @@ import org.apache.openjpa.kernel.StoreManager; import org.apache.openjpa.lib.util.Closeable; import org.apache.openjpa.lib.util.ReferenceMap; import org.apache.openjpa.lib.util.UUIDGenerator; -import org.apache.openjpa.lib.util.concurrent.ConcurrentHashMap; import org.apache.openjpa.lib.util.concurrent.ConcurrentReferenceHashMap; import org.apache.openjpa.meta.ClassMetaData; import org.apache.openjpa.meta.FieldMetaData; @@ -244,7 +243,8 @@ public class ImplHelper { Boolean isAssignable = null; Map assignableTo = (Map) _assignableTypes.get(from); if (assignableTo == null) { // "to" cache doesn't exist, so create it... - assignableTo = new ConcurrentHashMap(); + assignableTo = new ConcurrentReferenceHashMap(ReferenceMap.WEAK, + ReferenceMap.HARD); _assignableTypes.put(from, assignableTo); } else { // "to" cache exists... isAssignable = (Boolean) assignableTo.get(to);