SubjectDomainCombiner creates an instance of WeakHashMap. Key objects in this map are the "current" ProtectionDomain instances received via the combine method. Each "current" PD is mapped to a new PD instance that holds both the contents of the "current" PD, as well as the principals from the Subject associated with this combiner.
At the moment, the WeakHashMap values are regular strong references to the newly created PD "principal-based" instances. However, this is a problem because these values contain strong references to the corresponding key object (the "current" non-principal-based PD). Specifically, a "principal-based" PD contains strong references to the CodeSource, signer certs, PermissionCollection and ClassLoader objects in the "current PD". This prevents the key from being garbage-collected, resulting in an ever growing Map over time (assuming the SubjectDomainCombiner instance is shared across different ClassLoader instances).
To correct this problem, the newly created "principal-based" PD values must be stored as WeakReferences. This will allow the keys to become weakly referencable and therefore let Map entries become garbage collected as ClassLoader instances become weakly referencable.
Note that if the SubjectDomainCombiner instance is NOT shared across different ClassLoader instances, this problem is less severe. The code effectively behaves as it were using a regular HashMap as opposed to a WeakHashMap - entries never leave the Map via garbage collection. The size of the Map is roughly limited by the number of ClassLoader classpath elements.
JMX does share SubjectDomainCombiner instances across ClassLoaders, so this problem eventually results in an OutOfMemoryError (since the Map grows infinitely over time).
###@###.### 2005-1-18 22:49:03 GMT