0

I seem to be having a memory leak issue when using spring, hibernate, and tiles for my webapp. I think this might be caused by my application not cleaning up after itself between deployments. I deploy and undeploy a lot, since I'm currently just learning all of these frameworks.

What kind of things should I be doing to cleanup in my web application? I currently do nothing because I thought Java automatically did memory cleaning, however I'm pretty sure it doesn't do everything when it comes to spring since tomcat keeps complaining about permgen memory.

I'm confused as to whether or not I need to be running certain methods in order to keep things clean. I read about a spring hook that registers the application somewhere, then when it shuts down the application is cleaned up properly? I wasn't sure if something like that was necessary though in the new version of spring (3.1)

For example, tomcat keeps telling me that I'm not properly unregistering the JDBC driver (however I think tomcat does this automatically if it is detected).

I understand this is a hugely vague question, but if someone could mention certain things that need to be done to keep my application from leaking, I can google for them myself.

Thanks!

Fittersman
  • 625
  • 2
  • 11
  • 22
  • Does it result in a perm gen space error? – Ralph Jan 11 '12 at 06:21
  • Check if the deployment is proper by checking if there are any ERROR log statements in tomcat. Also, if tomcat is saying that JDBC driver is not registered properly, then it needs attention. Check if the jdbc driver library is present in classpath. – Gaurav Jan 11 '12 at 06:24

3 Answers3

2

Hibernate 4.0 introduced jboss-logging as a dependency which seems to cause permgen leaks (see https://issues.jboss.org/browse/JBLOGGING-66).

I'm not sure what can be done to properly fix it but as a workaround moving the jboss-logging jar into tomcats lib directory seems to work.

davidg
  • 695
  • 6
  • 8
1

Anyway, as long as possible, you should shut down your production tomcat before you deploy a new version. (This requrired to have two tomcats an a fail over mechanism, or you just accept that the service is down for one second longer, than just an update.)

To my knowlegs, this is the only way to make sure that a memory leak (consider the perm gen too) will not do any harmful thing.

Ralph
  • 118,862
  • 56
  • 287
  • 383
0

This sounds like issues on projects where I used Hibernate.

Hibernate generates proxies for every domain object you use. These proxies are kept under Permanent Generation space and they don't get cleaned up on application restarts/redeploys. Amount of memmory used by PermGen space is by default relatively small so you may try to increment it with the -XX:MaxPermSize java parameter. This may improve the time before you get an memmory error but there is not a complete solution I know to this problem. You will have to restart the tomcat it self eventually.

For the jdbc issue firstly if you manually use the connection make sure it's closed properly in a try catch finally block. If you don't use the connection object that way than it could be related again with Hibernate.

Murat Can ALPAY
  • 520
  • 2
  • 17
  • Yeah, I've increased the maxpermsize parameter to 256mb. That helps with the time between restarts, but I was hoping for some way to prevent from having to restart at all. Also. with the jdbc issue, I'll have to look into that. I'm not all that familiar with hibernate so I don't know if I have to do that myself, or if it does that for me? I assumed hibernate would take care of all that automatically – Fittersman Jan 12 '12 at 00:57