I was trying to render an image and I was getting out of memory error in this line.
try{
BufferedImage image = pdfRenderer.renderImageWithDPI(page-1, 300,ImageType.GRAY);
ImageIOUtil.writeImage(image,"G:/Trial/tempImg.png", 300);
int bpp = image.getColorModel().getPixelSize();
int bytespp = bpp / 8;
int bytespl = (int) Math.ceil(image.getWidth() * bpp / 8.0);
int height = image.getHeight();
int width = image.getWidth();
TessAPI1.TessBaseAPISetImage(handle, ImageIOHelper.convertImageData(image), width, height, bytespp, bytespl);
TessAPI1.TessBaseAPISetPageSegMode(handle, TessPageSegMode.PSM_AUTO);
//codes
}
finally
{
//some code so that this function could be called again with next pdf
//some code to release resources
}
In this code segment first I am rendering a particular page from a pdf document to BufferedImage and then I am converting the bufferedImage to Bytes before providing it to tesseract. It is at this point that I am getting an Out of memory Error.
Normally when you get an out of memory error you get one more message beside it , either out of heap or out of perm. But, here I am getting just an out of memory error. Please explain this.
When I was debugging this code I observed that the code doesn't terminate at the line where I am converting image to byte but rather it goes to finally block (I am using try and finally block for this code segment). So I put a continue in my finally and voila my code was running perfectly for next set of pdfs.
So my question is how is my program not exiting after the out of memory error(not that I want it to not work) but If memory is really full then how can the code load next set of pdfs. An insight on this would be really wonderful. Thanks
P.S - This problem is solved due to that hack and my code is working but I am curious as to why all this is happening.