Potential memory leak using BufferedImage and ImageIO in a servlet?

  • Thread starter Richard Corfield
  • Start date
R

Richard Corfield

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top