-
Bug
-
Resolution: Cannot Reproduce
-
P3
-
6u10, 7, 8, 9
-
x86
-
windows_xp
FULL PRODUCT VERSION :
JRE 1.6.0_13, 1.6.0_14
ADDITIONAL OS VERSION INFORMATION :
Windows XP/Vista
possibly, other platforms
A DESCRIPTION OF THE PROBLEM :
JPEGImageReader leaks memory even if its dispose() method is called.
This is especially noticeable when reading several huge images in a row (30000x22500 pixels each in our case). Each image is read in small stripes to avoid out-of-memory errors, and after the whole image is read, the reader is disposed().
In out test, we were able to read only two images in such a manner; the third try produces an OOM error. As we need this functionality in an applet, we test with the default heap size of 64 MBs.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to read several images of size 30000x22500 pixels, as described in the enclosed listing.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
All images are read normally.
ACTUAL -
Some images are read successfully, but then an out-of-memory exception is thrown.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferByte.<init>(Unknown Source)
at java.awt.image.Raster.createInterleavedRaster(Unknown Source)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(Unknown Source)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readRaster(Unknown Source)
at com.aurigma.jirtest.JIRTest.init(JIRTest.java:56)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
for (int i = 0; i < 5; ++i)
{
System.out.println("Reading Image " + i);
ImageReader reader = null;
try
{
File file = new File("C:/Lynx/Bug10142_" + i + ".jpg");
ImageInputStream inStream = ImageIO.createImageInputStream(file);
Iterator<ImageReader> iterator = ImageIO.getImageReaders(inStream);
// look for a suitable reader
while (iterator.hasNext())
{
reader = iterator.next();
if (reader != null)
break;
}
if (reader != null)
reader.setInput(inStream);
else
throw new RuntimeException("Cannot find a suitable reader");
int height = reader.getHeight(0);
int width = reader.getWidth(0);
int defaultStripeHeight = 123;
int nextRowToDecode = 0;
// read data in small stripes to avoid OOM errors when processing huge images
while (nextRowToDecode < height)
{
int stripeHeight = Math.min(defaultStripeHeight, height - nextRowToDecode);
ImageReadParam param = reader.getDefaultReadParam();
param.setSourceRegion(new Rectangle(0, nextRowToDecode, width, stripeHeight));
Raster stripe = reader.readRaster(0, param);
// ...stripe processing would be done here...
nextRowToDecode += stripeHeight;
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
finally
{
if (reader != null)
reader.dispose();
}
}
---------- END SOURCE ----------
JRE 1.6.0_13, 1.6.0_14
ADDITIONAL OS VERSION INFORMATION :
Windows XP/Vista
possibly, other platforms
A DESCRIPTION OF THE PROBLEM :
JPEGImageReader leaks memory even if its dispose() method is called.
This is especially noticeable when reading several huge images in a row (30000x22500 pixels each in our case). Each image is read in small stripes to avoid out-of-memory errors, and after the whole image is read, the reader is disposed().
In out test, we were able to read only two images in such a manner; the third try produces an OOM error. As we need this functionality in an applet, we test with the default heap size of 64 MBs.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Try to read several images of size 30000x22500 pixels, as described in the enclosed listing.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
All images are read normally.
ACTUAL -
Some images are read successfully, but then an out-of-memory exception is thrown.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.lang.OutOfMemoryError: Java heap space
at java.awt.image.DataBufferByte.<init>(Unknown Source)
at java.awt.image.Raster.createInterleavedRaster(Unknown Source)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readInternal(Unknown Source)
at com.sun.imageio.plugins.jpeg.JPEGImageReader.readRaster(Unknown Source)
at com.aurigma.jirtest.JIRTest.init(JIRTest.java:56)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
for (int i = 0; i < 5; ++i)
{
System.out.println("Reading Image " + i);
ImageReader reader = null;
try
{
File file = new File("C:/Lynx/Bug10142_" + i + ".jpg");
ImageInputStream inStream = ImageIO.createImageInputStream(file);
Iterator<ImageReader> iterator = ImageIO.getImageReaders(inStream);
// look for a suitable reader
while (iterator.hasNext())
{
reader = iterator.next();
if (reader != null)
break;
}
if (reader != null)
reader.setInput(inStream);
else
throw new RuntimeException("Cannot find a suitable reader");
int height = reader.getHeight(0);
int width = reader.getWidth(0);
int defaultStripeHeight = 123;
int nextRowToDecode = 0;
// read data in small stripes to avoid OOM errors when processing huge images
while (nextRowToDecode < height)
{
int stripeHeight = Math.min(defaultStripeHeight, height - nextRowToDecode);
ImageReadParam param = reader.getDefaultReadParam();
param.setSourceRegion(new Rectangle(0, nextRowToDecode, width, stripeHeight));
Raster stripe = reader.readRaster(0, param);
// ...stripe processing would be done here...
nextRowToDecode += stripeHeight;
}
}
catch (Exception e)
{
System.out.println(e.getMessage());
}
finally
{
if (reader != null)
reader.dispose();
}
}
---------- END SOURCE ----------