Original Posting Date: 11/26/2008.
There is an excellent blog that describes classloaders and memory leaks in Java: Frank Kievet Blog. The next entry in the blog shows a new tool from Java 1.6 that can be used to isolate memory leaks.
In summary
The first memory leak can be removed by modifying XMLHelper. There is a static variable that is not used anywhere, except in Configuration. By removing the variable from XMLHelper and removing the reference to it (replace with null) in Configuration, the leak goes away.
The second memory leak is more entwined in cglib. The leak can be removed by having cglib loaded by a different classloader than the one for the web app. The solution is to move the cglib jar and the asm jar to the shared lib directory of Tomcat.
I have recompiled hibernate and created zip files for the jar files that still belong in the web app and the two that belong in the shared lib directory of Tomcat. If you are using a system and do not have access to the shared lib folder (or common lib folder), then place these jars in the web app with the understanding that you will run out of memory eventually.
unzip ~downeyt/cs/public_html/cgs4854/hibernate-3.2.jars/webapp.jars.zip
After you upload the WAR file, please delete these JAR files from the lib dir on ocelot.
import org.hibernate.validator.NotNull; import org.hibernate.validator.Pattern; import javax.persistence.Entity; import javax.persistence.Transient; import javax.persistence.Id; import javax.persistence.GeneratedValue; @Entity public class RequestDataPersistent { protected Long id; @Id @GeneratedValue public Long getId() { return id; } private void setId(Long id) { this.id = id; } //Add additional properties for your bean ... }
setenv CLASSPATH {$CLASSPATH}:$HOME/cgs4854/webapps/book/WEB-INF/lib/ejb3-persistence.jar setenv CLASSPATH {$CLASSPATH}:$HOME/cgs4854/webapps/book/WEB-INF/lib/hibernate-3.2.jar setenv CLASSPATH {$CLASSPATH}:$HOME/cgs4854/webapps/book/WEB-INF/lib/hibernate-annotations-3.2.jar setenv CLASSPATH {$CLASSPATH}:$HOME/cgs4854/webapps/book/WEB-INF/lib/log4j-1.2.11.jar setenv CLASSPATH {$CLASSPATH}:$HOME/cgs4854/webapps/book/WEB-INF/lib/commons-beanutils.jar