- Feb 8, 2004
- 12,603
- 9
- 81
So this is fun... i've inherited an application with a potential memory leak.
It uses Java 6, Jetty 6.xx and the Java Pesistence API. Its purpose is to display the status of backup software backups. It dosent actually do any backups itself or anything. Pretty sure this is 32 bit Java it runs on, its on Centos 5, 32 bit. It uses the Java Service Wrapper from Tanuki software.
Unfortunately it spews "java.lang.OutOfMemoryError: Java heap space" errors sometimes. I have narrowed it down to one particular page that causes the issue. This page refreshes via an AJAX call every 30 seconds and brings back a hefty bit of data. It communicates with a servlet that returns a json. I've poked though the code and looked at various things, resources that need closed... EntityManager, that gets closed in a finally clause etc. It all looks fine. One weird thing is the EntityManager object contains a transaction variable which contains another EntityManager which contains another transaction etc etc. This chain of EntityManagers seems to be extremely deep. I don't know if this is normal or not...
I have run VisualVM memory profiler on my development version and it looks like T4CStatement, GregorianCalander and ZoneInfo objects never get garbage collected. They sit around for 300+ generations (which I gather is bad). But im not 100% sure, maybe they only get garbage collected after they take up a certain amount of space and it dosent matter how many instances there are.
This may not even be a memory leak it might just need more memory and im seeing the limits of a 32 bit app on a 32 bit OS.
My half baked solution is possibly to call System.gc() either on every invocation of the troublesome servlet (or every 10th invocation, I really need to extensively google the implications of calling System.gc() before I do this) and setting the page to refresh every 60 seconds instead of 30. Im going to try manually forcing a garbage collection by clicking the button in VisualVM on Monday to see if it picks up those objects that sit around for 300+ generations.
tl;dr Given a 32 bit Java 6 application using jetty 6 and a Java Service Wrapper on Centos 5 32 bit, is there any surefire way to know if there is a memory leak? Some objects sit around for 300+ (potentially more) generations in VisualVM memory profiler. These are: T4CStatement, GregorianCalander and ZoneInfo. Also the JPA is used, the EntityManager object (although it is closed) contains a transaction variable which contains another EntityManager etc etc. This chain of EntityManagers seems to be extremely deep. I don't know if this is normal or not...
It uses Java 6, Jetty 6.xx and the Java Pesistence API. Its purpose is to display the status of backup software backups. It dosent actually do any backups itself or anything. Pretty sure this is 32 bit Java it runs on, its on Centos 5, 32 bit. It uses the Java Service Wrapper from Tanuki software.
Unfortunately it spews "java.lang.OutOfMemoryError: Java heap space" errors sometimes. I have narrowed it down to one particular page that causes the issue. This page refreshes via an AJAX call every 30 seconds and brings back a hefty bit of data. It communicates with a servlet that returns a json. I've poked though the code and looked at various things, resources that need closed... EntityManager, that gets closed in a finally clause etc. It all looks fine. One weird thing is the EntityManager object contains a transaction variable which contains another EntityManager which contains another transaction etc etc. This chain of EntityManagers seems to be extremely deep. I don't know if this is normal or not...
I have run VisualVM memory profiler on my development version and it looks like T4CStatement, GregorianCalander and ZoneInfo objects never get garbage collected. They sit around for 300+ generations (which I gather is bad). But im not 100% sure, maybe they only get garbage collected after they take up a certain amount of space and it dosent matter how many instances there are.
This may not even be a memory leak it might just need more memory and im seeing the limits of a 32 bit app on a 32 bit OS.
My half baked solution is possibly to call System.gc() either on every invocation of the troublesome servlet (or every 10th invocation, I really need to extensively google the implications of calling System.gc() before I do this) and setting the page to refresh every 60 seconds instead of 30. Im going to try manually forcing a garbage collection by clicking the button in VisualVM on Monday to see if it picks up those objects that sit around for 300+ generations.
tl;dr Given a 32 bit Java 6 application using jetty 6 and a Java Service Wrapper on Centos 5 32 bit, is there any surefire way to know if there is a memory leak? Some objects sit around for 300+ (potentially more) generations in VisualVM memory profiler. These are: T4CStatement, GregorianCalander and ZoneInfo. Also the JPA is used, the EntityManager object (although it is closed) contains a transaction variable which contains another EntityManager etc etc. This chain of EntityManagers seems to be extremely deep. I don't know if this is normal or not...