Strange memory leak when reading serialized data in Tomcat web app
I'm deploying a relatively simple web application to Tomcat 7.0.8 (JVM 1.6).
The app registers a ServletContextListener and has a single resource called "data" located in WEB-INF. The "data" file contains a single serialized in开发者_运维问答stance of a simple class called Data. Data has a few public String and Integer fields but nothing else. It implements Serializable and defines its own serialVersionUID.
In the contest listener, contextInitialized() does the following:
- Get an InputStream to "data" from the ServletContext,
- Create an ObjectInputStream from the InputStream,
- Read a single object from the ObjectInputStream,
- Cast it to the type "Data",
- Write the field values to System.out,
- Close the ObjectInputStream and its backing InputStream.
Everything seems to work fine. However when I stop the webapp through Tomcat's manager application, then check for memory leaks, Tomcat informs me that my app leaked memory when it was stopped.
I'm positive the issue is with the Data class, since when I serialize a String or Integer I don't see the leak.
Any thoughts?
If this file is read in once on initialization of the web app, how is a memory leak significant? Does it even merit the title?
Memory leaks are significant to Tomcat and all app servers because they're intended to stay alive for a long time. Memory leaks are an issue only if they show up over a longer period of time.
Your instincts are good, but your procedures are flawed in my opinion.
I'd recommend that you use a better tool - the Visual VM that's bundled with JDK 6 and higher - and that you monitor your Tomcat while it's being used in a manner that's closer to your real production needs.
You can't draw any conclusion regarding memory leaks from a single request.
精彩评论