Index: src/org/python/core/PyType.java =================================================================== --- src/org/python/core/PyType.java (revision 7066) +++ src/org/python/core/PyType.java (working copy) @@ -1251,9 +1257,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); Index: src/org/python/util/Generic.java =================================================================== --- src/org/python/util/Generic.java (revision 7066) +++ src/org/python/util/Generic.java (working copy) @@ -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(); } + public static Map synchronizedWeakHashMap() { + return Collections.synchronizedMap(new WeakHashMap()); + } + + /** * Makes a ConcurrentMap using generic types inferred from whatever this is being * assigned to.