From: <zy...@us...> - 2010-06-23 20:25:14
|
Revision: 7067 http://jython.svn.sourceforge.net/jython/?rev=7067&view=rev Author: zyasoft Date: 2010-06-23 20:25:08 +0000 (Wed, 23 Jun 2010) Log Message: ----------- PyType#class_to_type should only have weak ref to Java classes being so mapped - this is important so that GC can occur on these classes Modified Paths: -------------- trunk/jython/src/org/python/core/PyType.java trunk/jython/src/org/python/util/Generic.java Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2010-06-16 14:46:34 UTC (rev 7066) +++ trunk/jython/src/org/python/core/PyType.java 2010-06-23 20:25:08 UTC (rev 7067) @@ -1251,9 +1251,11 @@ return newtype; } + // XXX what's the proper scope of this synchronization? given module import lock, might be + // ok to omit this sync here... public static synchronized PyType fromClass(Class<?> c) { if (class_to_type == null) { - class_to_type = Generic.map(); + class_to_type = Generic.synchronizedWeakHashMap(); addFromClass(PyType.class, null); } PyType type = class_to_type.get(c); Modified: trunk/jython/src/org/python/util/Generic.java =================================================================== --- trunk/jython/src/org/python/util/Generic.java 2010-06-16 14:46:34 UTC (rev 7066) +++ trunk/jython/src/org/python/util/Generic.java 2010-06-23 20:25:08 UTC (rev 7067) @@ -6,12 +6,14 @@ import java.util.AbstractSet; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -56,6 +58,11 @@ return new HashMap<K, V>(); } + public static <K, V> Map<K, V> synchronizedWeakHashMap() { + return Collections.synchronizedMap(new WeakHashMap<K, V>()); + } + + /** * Makes a ConcurrentMap using generic types inferred from whatever this is being * assigned to. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |