Out Of memory Exception using OCR Java


I am getting an Out Of Memory Exception: Java Heap space at the statement:

ocr.setResource(new FileInputStream(resourcesFolderPath));

I have downloaded the latest version of Aspose OCR for Java (1.9.0) and the resources zip file available at the URL:


Attached herewith is the BMP file I am using for the purpose of Text Extraction, with type 16 Arial font. The jars ocr-aspose1.9-jdk16 and aspose1.9-jdk14 have both been included and built into the project.

I am using JDK 7 on Eclipse on Windows 7 platform.

Thanks in Advance.

The code is the following, as available on your website:

import com.aspose.ocr.;

import java.io.;

public class OCRCheck{

	public static void main(string[] args)


		String imagePath = “D://dump//OCR//Sample.bmp”;

		String resourcesFolderPath = “D://dump//OCR//resource.zip”;

		OcrEngine ocr = new OcrEngine();

		ocr.setResource(new FileInputStream(resourcesFolderPath));



		ILanguage language = Language.load(“english”);


		try {

		if (ocr.process()) {

		System.out.println("\ranswer -> " + ocr.getText());


		} catch (Exception e) {



	}//end of main
}//end of class

And also, I have already increased the heap space available to the JRE to 1 GB.

Hi Sabhya,

Thank you for contacting Aspose support.

We have evaluated your presented scenario on our end while using the latest version of Aspose.OCR for Java 1.9.0. Unfortunately, we are unable to observe any exception when Java Heap size is set to 512m.

In order to troubleshoot this incident further please make sure you are using the latest version of Aspose.OCR for Java 1.9.0 and its corresponding resource file . Please note, each release of Aspose.OCR component uses specific resources therefore if you are using any older resources, you may get undesired results or errors while execution of your program. Once above is confirmed, please try extracting the resource archive (Aspose.OCR.1.9.0.Resources.zip) to make sure that the downloaded archive isn’t corrupted or damaged. At last, please ensure to set an adequate heap size for your JRE. As narrated earlier, we have tested the scenario with 512m Java Heap size, and didn’t encounter any problem, therefore you may set it to 512m on your end as well. If you are using Eclipse IDE, please follow the instructions provided on the below link to set the Java Heap size.


In case the problem persists, please provide details of your environment, so we could simulate it to re-evaluate the scenario on our end. Please note, we are interested in Operating System version, Operating System Architecture (32bit/64bit), JRE and total RAM installed on the machine.