The gc collection of unreferenced classes is dependent on the gc of their classloader. Only when the classloader is dropped the WeakHashMap will remove the cached classes.
In most cases, as in mine, this is the WebApp class loader. As our web application tries to connect 400+ DBs, all in the context initialisation, this loader of course remains, so the PermGen runs full.
I think some issues, found on the INet, with PermGen errors in development systems are quite similar, where the Appserver fails to dereference old WebApp class loaders after a hot deploy (like here:
http://forum.springframework.org/showthread.php?t=21383)
I think enabling the cache will help in cases where many SessionFactories are created based on the same mapping, while the classloade remains (like here:
http://forum.hibernate.org/viewtopic.ph ... emoryerror).
It will of course not help with PermGen errors from using mappings for 1900+ different tables like here:
http://forum.hibernate.org/viewtopic.ph ... ht=permgen.