tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <Yoav.Shap...@mpi.com>
Subject RE: [Slightly OT] coercing AWT/image libraries to release resources
Date Mon, 25 Oct 2004 12:56:08 GMT

Hi,
A profiler would show you what references are being kept, so that might
be helpful in knowing what to flush (assuming it's possible at all --
not a trivial assumption with AWT).  In any case, so what if the
ImageIcon takes 30MB?  

Yoav Shapira http://www.yoavshapira.com
 

>-----Original Message-----
>From: Robert Hunt [mailto:robert-hunt@comcast.net]
>Sent: Saturday, October 23, 2004 9:35 AM
>To: tomcat-user@jakarta.apache.org
>Subject: [Slightly OT] coercing AWT/image libraries to release
resources
>
>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: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




This e-mail, including any attachments, is a confidential business communication, and may
contain information that is confidential, proprietary and/or privileged.  This e-mail is intended
only for the individual(s) to whom it is addressed, and may not be saved, copied, printed,
disclosed or used by anyone else.  If you are not the(an) intended recipient, please immediately
delete this e-mail from your computer system and notify the sender.  Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message