Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

Hi Team,

I purchased this tool last week and try to redact pdf files. But after 2-3 file it gives me this error. Any file size limitation is there?

Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at com.groupdocs.redaction.internal.c.a.ms.d.i.y.pe(Unknown Source)
at com.groupdocs.redaction.internal.c.a.ms.d.i.y.is(Unknown Source)
at com.groupdocs.redaction.integration.m.a(Unknown Source)
at com.groupdocs.redaction.integration.m.a(Unknown Source)
at com.groupdocs.redaction.integration.m.replaceText(Unknown Source)
at com.groupdocs.redaction.redactions.ExactPhraseRedaction.applyTo(Unknown Source)
at com.groupdocs.redaction.b.a(Unknown Source)
at com.groupdocs.redaction.Redactor.apply(Unknown Source)
at com.gigaforce.redaction.ApplyMultipleRedactions3.run(ApplyMultipleRedactions3.java:81)
at com.gigaforce.redaction.MainClass.main(MainClass.java:13)

@giga.neeraj

You have to increase Java heap space using the -Xmx flag as follows:

java -Xmx2048m 

You may assign 3 or 4 gigs of memory and let us know if issue persists.

There is no file limitation or any such thing. However, if you are evaluating the API without a license, you may face evaluation limitations.

I have already increased to 4GB for that but no luck. The same error persists.
Can you please tell me the Root Cause of this problem.

The product is not mature yet to be tested,

@giga.neeraj

Normally, we don’t face this error. However, in order to investigate it, we need following details from you:

  • API version that you are using (e.g. 20.6, 20.9)
  • Sample application
  • Problematic files

Usually, this error is thrown when the Java Virtual Machine cannot allocate an object because it is out of memory, and no more memory could be made available by the garbage collector.

Therefore you pretty much have two options:

  • Increase the default memory your program is allowed to use using the -Xmx option (for instance for 1024 MB: -Xmx1024m)

  • Modify your program so that it needs less memory, using less big data structures and getting rid of objects that are not any more used at some point in your program

Increasing the heap sizeis a bad solution, 100% temporary. It will crash again in somewhere else. To avoid these issues, write high performance code:

  • Use local variables wherever possible.
  • Make sure you select the correct object (EX: Selection between String, StringBuffer and StringBuilder)
  • Use a good code system for your program(EX: Using static variables VS non static variables)
  • Other stuff which could work on your code.
  • Try to move with Multy Threading
1 Like

@lingmaaki

Yes, it could improve the performance.