I noticed the memory usage of my Ant tasks was growing large so I ran Ant with the Heap analysis tool and got the follow results.
Top Instance Counts of classes 28074 instances of class java.lang.String 27532 instances of class [C 24360 instances of class java.util.Hashtable$Entry 15961 instances of class sun.tools.java.Identifier <-- 3588 instances of class sun.tools.java.ClassType 2904 instances of class sun.tools.java.MethodType 2769 instances of class [Lsun.tools.java.Type; 1044 instances of class java.lang.Class 366 instances of class [Ljava.lang.Class; 324 instances of class java.util.SimpleTimeZone 253 instances of class java.util.HashMap$Entry 250 instances of class [B 239 instances of class [S 171 instances of class java.lang.reflect.Method 138 instances of class [Ljava.util.Hashtable$Entry; 135 instances of class java.util.jar.Attributes$Name 128 instances of class java.util.Hashtable ... Example root path to a sun.tools.java.Identifier Static reference from sun.tools.java.Identifier.hash (from class sun.tools.java.Identifier) : --> [EMAIL PROTECTED] (32 bytes) (field table:) --> Instance of [Ljava.util.Hashtable$Entry;@0x088a1409 (192124 bytes) (Element 28105 of Instance of [Ljava.util.Hashtable$Entry;:) --> [EMAIL PROTECTED] (16 bytes) (field value:) --> [EMAIL PROTECTED] (16 bytes) I deduce from this that sun.tools.java.Identifier has a static Hashtable field called hash which maps identifier names as Strings to Identifier objects, probably for interning. The problem with this is that since javac runs in the same JVM it holds onto 4 objects (Hashtable entry, Identifier, String, char array) for every unique Java language identifer ever seen since the build started. Solution proposed: run calls to javac inside their own ClassLoader Comments ?
