Potential memory leak using BufferedImage and ImageIO in a servlet?

Discussion in 'Java' started by Richard Corfield, Mar 4, 2004.

  1. I wonder if there is a known memory leak using BufferedImage and ImageWriter in
    a servlet. I'm using the static write method of ImageIO with a BufferedImage
    that I allocate for each request.

    I'm running on:
    Jakarta Tomcat 5.0.19,
    Sun JDK 1.4.2_01
    Linux, both Red Hat and Debian

    The two servlets I have make images for a progress bar, and a representation of
    an Oracle Queue. The parameters are passed in as part of the request. I have JSP
    tag files which encapsulate calling them, so I have <local:BarGraph> and
    <local:QueueDisplay> tags in my pages. The basics of the HttpServlet code are:

    /** Return the width to be produced for this request */
    protected abstract int getWidth(HttpServletRequest request);

    /** Return the height to be produced for this request */
    protected abstract int getHeight(HttpServletRequest request);

    /** Paint the graphic for this request */
    protected abstract void paint(Graphics2D g, HttpServletRequest request);

    /* HTTP Request handler */
    protected void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException
    BufferedImage oImage = new BufferedImage(getWidth(request),
    Graphics2D g = oImage.createGraphics();


    OutputStream out = response.getOutputStream();


    I notice that there is no dispose method on the BufferedImage. I also notice
    that the servlet only works if I have a reachable X server. Presumably
    BufferedImage, or awt, needs an X connection. On the RedHat box this has to be
    VNCServer, because the machine itself is headless.

    - Richard
    Richard Corfield, Mar 4, 2004
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.