On 11/28/05, kurrele wrote: > Hi to everyone!! This is my first email to this list, hope is the correct > one. > > I've been analyzing my code with a profiler (JProbe) because I was getting > an > OutOfMemoryException after a few redeploys of my application. > > After some tests, it turned out that my static fields were not GCed after > redeploying, getting stuck with the classloader which loaded my classes. > > After that, I searched the bugzilla and found > *Bug# *(Memory Leak in Classloader/Manager deploy/undeploy)*:* > 20758 > where it says that the bug has been FIXED. > > I tested it in Tomcat 4.1.24 and 5.0.28 getting the same result (memory leak > in static fields). > > I attach here the servlet and singleton of my simple test webapp. > > --------------------------------------------------------------------------------------------------------------------------- > public class Test extends HttpServlet > { > > MySingleton singleton = MySingleton.getInstance(); > > public void init(ServletConfig config) throws ServletException > { > super.init(config); > > } > > public void destroy() > { > singleton = null; > } > > protected void processRequest(HttpServletRequest request, > HttpServletResponse response) > throws ServletException, IOException > { > response.setContentType("text/html"); > PrintWriter out = response.getWriter(); > out.println("JProbe TEST > singletonJProbe TEST > singleton
"); > out.close(); > } > protected void doGet(HttpServletRequest request, HttpServletResponse > response) > throws ServletException, IOException > { > processRequest(request, response); > } > > protected void doPost(HttpServletRequest request, HttpServletResponse > response) > throws ServletException, IOException > { > processRequest(request, response); > } > } > > > ------------------------------------------------------------------------------------------------------------------------------------- > public class MySingleton > { > > private static MySingleton _instance = new MySingleton(); > > public byte[] _charWidths = new byte[1024*1024]; // 1Meg mem > allocation!!. > > private MySingleton() > {} > > public static MySingleton getInstance() > { > return _instance; > } > > public void finalize() > { > System.out.println("!!! END-MySingleton !!!"); > _instance = null; > } > } > > > ------------------------------------------------------------------------------------------------------------------------------------- > > After redeploying this simple webapp a 1Meg leak can be found due to > MySingleton not being GCed. > > Please I want to know If I'm leaving out something, the bug is not really > fixed or I need to take another approach. This issue also affects Hibernate. As it doesn't seem to be a Tomcat bug, but would be good to have a fix for, I've added possible workarounds for that (reflection code which sets as many static fields as possible to null in loaded classes when stopping the classloader) in the latest Tomcat code (which you need to get from SVN). It would need testing. -- xxxxxxxxxxxxxxxxxxxxxxxxx Rmy Maucherat Developer & Consultant JBoss Group (Europe) SRL xxxxxxxxxxxxxxxxxxxxxxxxx --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org