Index: src/main/org/apache/tools/ant/IntrospectionHelper.java =================================================================== RCS file: /home/cvspublic/ant/src/main/org/apache/tools/ant/IntrospectionHelper.java,v retrieving revision 1.85 diff -u -r1.85 IntrospectionHelper.java --- src/main/org/apache/tools/ant/IntrospectionHelper.java 12 Jun 2004 16:51:09 -0000 1.85 +++ src/main/org/apache/tools/ant/IntrospectionHelper.java 22 Jul 2004 22:36:07 -0000 @@ -18,6 +18,8 @@ package org.apache.tools.ant; import java.io.File; +import java.lang.ref.Reference; +import java.lang.ref.WeakReference; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -26,6 +28,8 @@ import java.util.Hashtable; import java.util.List; import java.util.Locale; +import java.util.Map; +import java.util.WeakHashMap; import org.apache.tools.ant.types.EnumeratedAttribute; import org.apache.tools.ant.taskdefs.PreSetDef; @@ -78,9 +82,9 @@ private Class bean; /** - * Helper instances we've already created (Class to IntrospectionHelper). + * Helper instances we've already created for particular classes. */ - private static Hashtable helpers = new Hashtable(); + private static Map/*>*/ helpers = new WeakHashMap(); /** * Map from primitive types to wrapper classes for use in @@ -432,12 +436,7 @@ * @return a helper for the specified class */ public static synchronized IntrospectionHelper getHelper(Class c) { - IntrospectionHelper ih = (IntrospectionHelper) helpers.get(c); - if (ih == null) { - ih = new IntrospectionHelper(c); - helpers.put(c, ih); - } - return ih; + return getHelper(null, c); } /** @@ -455,12 +454,15 @@ */ public static synchronized IntrospectionHelper getHelper(Project p, Class c) { - IntrospectionHelper ih = (IntrospectionHelper) helpers.get(c); + Reference/**/ r = (Reference) helpers.get(c); + IntrospectionHelper ih = r != null ? (IntrospectionHelper) r.get() : null; if (ih == null) { ih = new IntrospectionHelper(c); - helpers.put(c, ih); - // Cleanup at end of project - p.addBuildListener(ih); + helpers.put(c, new WeakReference(ih)); + if (p != null) { + // Cleanup at end of project + p.addBuildListener(ih); + } } return ih; }