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<http://issues.apache.org/bugzilla/show_bug.cgi?id=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("<html><head><title>JProbe TEST
singleton</title></head><body><b>JProbe TEST
singleton</b><BR></body></html>");
        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.

Thanks.

 Juan F. S. (Spain).

Reply via email to