I've got a servlet that produces thumbnail images on-the-fly (using TC 5.0.25, JDK 1.4.2). Once the servlet becomes active, it gobbles about 30mb per servlet/instance. I've gone through and tried to apply as many flush()/dispose()/gc()/etc. methods as I could find, but still, the memory remains allocated. Has anyone found a way to coerce the AWT (or appropriate Java imaging class) into releasing the memory?



The code (from doGet( request, response) method):
====================================================
ImageIcon imgIcon = null;
Image img = null;
try {
imgIcon = new ImageIcon( jpegFile ); // this is the point at which memory swells to like 30mb.
}
catch ( Exception e )
{
e.printStackTrace();
response.sendError( HttpServletResponse.SC_NOT_FOUND, filename );
}
img = imgIcon.getImage();
imgIcon = null;



// Determine the scale. double scale = Math.min( (double) h / (double) img.getHeight( null ) , (double) w / (double) img.getWidth( null ) );


// Determine size of new image. int scaledW = (int)( scale * img.getWidth( null ) ); int scaledH = (int)( scale * img.getHeight( null ) );

BufferedImage thumb = new BufferedImage( scaledW, scaledH, BufferedImage.TYPE_INT_RGB );

       // Set the scale.
       AffineTransform tx = new AffineTransform();
       if ( scale < 1.0d ) tx.scale( scale, scale );

       // Paint image.
       Graphics2D g2d = thumb.createGraphics();
       g2d.drawImage( img, tx, null );
       g2d.dispose();
       g2d = null;

       img.flush();
       img = null;

       OutputStream out = response.getOutputStream();
       ImageIO.write( thumb, ext, out );

       thumb.flush();
       thumb = null;
====================================================



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to