Skip to main content

leaking MemoryCachedImageOutputStreams

1 reply [Last post]
langfors
Offline
Joined: 2005-11-17
Points: 0

Our company produces an intranet imaging web application. We use ImageIO extensively in our product and love its simplicity and speed. We have several dozen clients hosting our app successfully on many platforms. We have one client who strangely leaks MemoryCachedImageoutputStreams when running our code. (We believe it is related to the following snippet)

Does anyone know if this is a manifestation of this bug?

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6331429

Does anyone have any insight or experience with this type of issue?

We mandate that our clients use JDK 1.6.0_21 and ImageIO 1.2.

Thanks

Sean

</p>
<p>OutputStream out = servlet.getOutputStream();<br />
ImageOutputStream  mcios = null;</p>
<p>try<br />
{<br />
    mcios = ImageIO.createImageOutputStream(out);<br />
    final Iterator writers = ImageIO.getImageWritersByFormatName("jpeg");<br />
    final ImageWriter writer = writers.next();<br />
    final ImageWriteParam writeParam =  writer.getDefaultWriteParam();</p>
<p>    writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);<br />
    writeParam.setCompressionQuality(1.0f);<br />
    writer.setOutput(mcios);<br />
    if (tile != null)<br />
    {<br />
        writer.write(null, new IIOImage(tile, null, null), writeParam);<br />
    }<br />
    writer.dispose();<br />
}<br />
catch (final IOException ioe)<br />
{<br />
    ioe.printStackTrace();<br />
}<br />
finally<br />
{<br />
    if (mcios != null)<br />
    {<br />
        try<br />
        {<br />
            mcios.flush();<br />
            mcios.close();<br />
        }<br />
        catch (final IOException e)<br />
        {<br />
            logger.warn("Warning: could not close MemoryCacheImageOutputStream");<br />
        }<br />
    }</p>
<p>    try<br />
    {<br />
        out.flush();<br />
        out.close();<br />
    }<br />
    catch (final IOException e)<br />
    {<br />
        // very unlikely<br />
        logger.warn("Warning: could not close OutputStream");<br />
    }<br />
}</p>
<p>

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
broumbroum
Offline
Joined: 2010-04-24
Points: 0

I'd recommend to instance a FileCacheImageOutputStream, since memorycacheimage.. does require the cache to be fully loaded in RAM.