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.
The java.lang.OutOfMemoryError: Java heap space you’re encountering is not caused by a fixed file size limitation. It is caused by insufficient JVM heap memory for the way the PDF redaction is being performed. As a result, heap usage gradually increases and eventually exceeds the configured maximum heap size, leading to this error.
Try the same process once after you increase the JVM heap size. If the issue appears even after increasing the heap memory, then it indicates to you about the memory retention during repeated redaction operations.
If that is the case, then capturing a heap dump at the time of failure would help identify what objects are retaining memory. Capture a heap dump at the time of failure. You can use this open-source yc-360 script. The yc-360 script is a simple script that captures 16 different artifacts from your application in a pristine manner, which are highly useful to troubleshoot production problems. With the heap dump file that you capture, you can analyze it and check for memory leaks, large object retention, or excessive caching.
To learn more interesting details about the OutOfMemoryError: Java heap space error, you can check out this blog, “How to Solve OutOfMemoryError: Java heap space”. This will give you more insights about this Java Heap Space error.