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),
    getHeight(request),
    BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = oImage.createGraphics();

    paint(g,request);

    response.setContentType("image/png");
    OutputStream out = response.getOutputStream();
    ImageIO.write(oImage,"PNG",out);

    out.close();
    }

    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
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. F C
    Replies:
    2
    Views:
    5,218
  2. Davidski
    Replies:
    0
    Views:
    3,947
    Davidski
    Nov 5, 2004
  3. Replies:
    8
    Views:
    662
    Jim Langston
    Aug 16, 2006
  4. cyl
    Replies:
    3
    Views:
    126
    Ilya Zakharevich
    Nov 13, 2008
  5. Fred Greer
    Replies:
    11
    Views:
    933
    Knute Johnson
    Jun 21, 2012
Loading...

Share This Page