Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

java.lang.OutOfMemoryError: Java heap space from SimpleRenderer #65

Open
daynok opened this issue Jan 25, 2019 · 2 comments
Open

java.lang.OutOfMemoryError: Java heap space from SimpleRenderer #65

daynok opened this issue Jan 25, 2019 · 2 comments
Labels

Comments

@daynok
Copy link

daynok commented Jan 25, 2019

Trying to evaluate ghost4j but am getting an outofmemory error on ghost4j 1.0.1
My env:
64 bit linux (arch)
Java 1.8.0_131

Tried multiple times to attach pdf to this ticket.. github kept giving me errors so created a repo with support files

  • Driver.java (test app)
  • Pro-Git.pdf (test pdf, 7.7M)

https://github.com/daynok/ghost4j-outofmemory

Ran pdfinfo on the pdf and as far as I can tell it looks good. Also opened the pdf in firefox without issue.

From what I can tell the outofmemory error gets thrown at
renderer.render(document);

I'm not sure if I'm doing something wrong programmatically or what.

End goal, convert pdf pages to png's.

package com.medata;

import java.io.File;
import org.ghost4j.document.PDFDocument;
import org.ghost4j.renderer.SimpleRenderer;

public class Driver {

    public static void main(String args[]) {
            try {
                    String sourcePath = args[0];
                    System.out.println("Reading files from path:" + sourcePath);

                    File[] fileList = new File(sourcePath).listFiles();

                    for(File pdfFile : fileList) {
                            System.out.println("starting to process file: " + pdfFile.getName());
                            long startIterTime = System.currentTimeMillis();
                            PDFDocument document = null;
                            SimpleRenderer renderer = null;

                            try {

                                    document = new PDFDocument();
                                    document.load(pdfFile);
                                    renderer = new SimpleRenderer();
                                    renderer.setResolution(300);
                                    renderer.render(document);
                            }
                            catch(Exception e) {
                                    throw e;
                            }
                            finally {
                                    renderer = null;
                                    document = null;
                            }
                            long totalIterTime = System.currentTimeMillis() - startIterTime;
                            System.out.println("file:" + pdfFile.getName() + " total time:" + totalIterTime + " ms, total time sec:" + (totalIterTime/1000));
                    }
            }
            catch(Exception e) {
                    e.printStackTrace();
            }
    }
@4F2E4A2E
Copy link
Collaborator

Hey @daynok 👋
Please provide the stacktrace, thanks

@ragwave
Copy link

ragwave commented Jul 27, 2021

Stack trace:

JNA: Callback org.ghost4j.Ghostscript$10@71b3bc45 threw the following exception:
java.lang.OutOfMemoryError: Java heap space
	at com.sun.jna.Pointer.getByteArray(Pointer.java:725)
	at org.ghost4j.Ghostscript$10.callback(Ghostscript.java:493)
	at sun.reflect.GeneratedMethodAccessor18.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.sun.jna.CallbackReference$DefaultCallbackProxy.invokeCallback(CallbackReference.java:470)
	at com.sun.jna.CallbackReference$DefaultCallbackProxy.callback(CallbackReference.java:500)
	at com.sun.jna.Native.invokeInt(Native Method)
	at com.sun.jna.Function.invoke(Function.java:383)
	at com.sun.jna.Function.invoke(Function.java:315)
	at com.sun.jna.Library$Handler.invoke(Library.java:212)
	at com.sun.proxy.$Proxy31.gsapi_init_with_args(Unknown Source)
	at org.ghost4j.Ghostscript.initialize(Ghostscript.java:350)
	at org.ghost4j.renderer.SimpleRenderer.run(SimpleRenderer.java:105)
	at org.ghost4j.renderer.AbstractRemoteRenderer.render(AbstractRemoteRenderer.java:86)
	at org.ghost4j.renderer.AbstractRemoteRenderer.render(AbstractRemoteRenderer.java:70)

	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
JNA: Callback org.ghost4j.Ghostscript$10@71b3bc45 threw the following exception:
java.lang.OutOfMemoryError: Java heap space
	at com.sun.jna.Pointer.getByteArray(Pointer.java:725)
	at org.ghost4j.Ghostscript$10.callback(Ghostscript.java:493)
	at sun.reflect.GeneratedMethodAccessor18.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at com.sun.jna.CallbackReference$DefaultCallbackProxy.invokeCallback(CallbackReference.java:470)
	at com.sun.jna.CallbackReference$DefaultCallbackProxy.callback(CallbackReference.java:500)
	at com.sun.jna.Native.invokeInt(Native Method)
	at com.sun.jna.Function.invoke(Function.java:383)
	at com.sun.jna.Function.invoke(Function.java:315)
	at com.sun.jna.Library$Handler.invoke(Library.java:212)
	at com.sun.proxy.$Proxy31.gsapi_init_with_args(Unknown Source)
	at org.ghost4j.Ghostscript.initialize(Ghostscript.java:350)
	at org.ghost4j.renderer.SimpleRenderer.run(SimpleRenderer.java:105)
	at org.ghost4j.renderer.AbstractRemoteRenderer.render(AbstractRemoteRenderer.java:86)
	at org.ghost4j.renderer.AbstractRemoteRenderer.render(AbstractRemoteRenderer.java:70)
	
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
JNA: Callback org.ghost4j.Ghostscript$10@71b3bc45 threw the following exception:
java.lang.OutOfMemoryError: Java heap space
JNA: Callback org.ghost4j.Ghostscript$10@71b3bc45 threw the following exception:
java.lang.OutOfMemoryError: Java heap space
JNA: Callback org.ghost4j.Ghostscript$10@71b3bc45 threw the following exception:
java.lang.OutOfMemoryError: Java heap space
JNA: Callback org.ghost4j.Ghostscript$10@71b3bc45 threw the following exception:
java.lang.OutOfMemoryError: Java heap space
JNA: Callback org.ghost4j.Ghostscript$10@71b3bc45 threw the following exception:
java.lang.OutOfMemoryError: Java heap space

Q. Is there a limit on no of pages that GS can process at once?
This error comes while processing a pdf with pages > 500. GS was able to process to 147 pages and post that it threw the error.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants