Skip to content

OutOfMemoryError: Java heap space when generating PDF #45

@wimdeblauwe

Description

@wimdeblauwe

I am using Asciidoc to write a book and have not had any issues so far to generate a PDF using Maven with the following versions:

        <asciidoctor-maven-plugin.version>2.0.0</asciidoctor-maven-plugin.version>
        <asciidoctorj.version>2.4.0</asciidoctorj.version>
        <asciidoctorj-pdf.version>1.5.3</asciidoctorj-pdf.version>

However, I added an extra chapter and now the build fails with:

[ERROR] Java heap space -> [Help 1]
java.lang.OutOfMemoryError: Java heap space
    at org.jruby.RubyString.newString (RubyString.java:498)
    at org.jruby.RubyString.newString (RubyString.java:493)
    at org.jruby.ext.zlib.JZlibInflate.flushOutput (JZlibInflate.java:109)
    at org.jruby.ext.zlib.JZlibInflate.internalFinish (JZlibInflate.java:329)
    at org.jruby.ext.zlib.ZStream.finish (ZStream.java:136)
    at org.jruby.ext.zlib.JZlibInflate.s_inflate (JZlibInflate.java:74)
    at org.jruby.ext.zlib.JZlibInflate$INVOKER$s$1$0$s_inflate.call (JZlibInflate$INVOKER$s$1$0$s_inflate.gen)
    at org.jruby.runtime.callsite.CachingCallSite.call (CachingCallSite.java:172)
    at uri_3a_classloader_3a_.gems.prawn_minus_2_dot_2_dot_2.lib.prawn.images.png.invokeOther61:inflate (uri:classloader:/gems/prawn-2.2.2/lib/prawn/images/png.rb:92)
    at uri_3a_classloader_3a_.gems.prawn_minus_2_dot_2_dot_2.lib.prawn.images.png.RUBY$method$initialize$0 (uri:classloader:/gems/prawn-2.2.2/lib/prawn/images/png.rb:92)
    at java.lang.invoke.DirectMethodHandle$Holder.invokeStatic (DirectMethodHandle$Holder)
    at java.lang.invoke.LambdaForm$MH/0x000000080076d440.invokeExact_MT (LambdaForm$MH)
    at org.jruby.internal.runtime.methods.CompiledIRMethod.call (CompiledIRMethod.java:108)
    at org.jruby.internal.runtime.methods.MixedModeIRMethod.call (MixedModeIRMethod.java:140)
    at org.jruby.runtime.callsite.CachingCallSite.call (CachingCallSite.java:182)
    at org.jruby.RubyClass.newInstance (RubyClass.java:918)
    at org.jruby.RubyClass$INVOKER$i$newInstance.call (RubyClass$INVOKER$i$newInstance.gen)
    at org.jruby.internal.runtime.methods.JavaMethod$JavaMethodZeroOrOneOrNBlock.call (JavaMethod.java:349)
    at org.jruby.runtime.callsite.CachingCallSite.call (CachingCallSite.java:172)
    at uri_3a_classloader_3a_.gems.prawn_minus_2_dot_2_dot_2.lib.prawn.images.invokeOther13:new (uri:classloader:/gems/prawn-2.2.2/lib/prawn/images.rb:92)
    at uri_3a_classloader_3a_.gems.prawn_minus_2_dot_2_dot_2.lib.prawn.images.RUBY$method$build_image_object$0 (uri:classloader:/gems/prawn-2.2.2/lib/prawn/images.rb:92)
    at java.lang.invoke.DirectMethodHandle$Holder.invokeStatic (DirectMethodHandle$Holder)
    at java.lang.invoke.LambdaForm$MH/0x000000080076d440.invokeExact_MT (LambdaForm$MH)
    at org.jruby.internal.runtime.methods.CompiledIRMethod.call (CompiledIRMethod.java:108)
    at org.jruby.internal.runtime.methods.MixedModeIRMethod.call (MixedModeIRMethod.java:140)
    at org.jruby.internal.runtime.methods.DynamicMethod.call (DynamicMethod.java:200)
    at org.jruby.runtime.callsite.CachingCallSite.call (CachingCallSite.java:172)
    at uri_3a_classloader_3a_.gems.asciidoctor_minus_pdf_minus_1_dot_5_dot_3.lib.asciidoctor.pdf.converter.invokeOther11:build_image_object (uri:classloader:/gems/asciidoctor-pdf-1.5.3/lib/asciidoctor/pdf/converter.rb:1499)
    at uri_3a_classloader_3a_.gems.asciidoctor_minus_pdf_minus_1_dot_5_dot_3.lib.asciidoctor.pdf.converter.RUBY$block$convert_image$6 (uri:classloader:/gems/asciidoctor-pdf-1.5.3/lib/asciidoctor/pdf/converter.rb:1499)
    at java.lang.invoke.DirectMethodHandle$Holder.invokeStatic (DirectMethodHandle$Holder)
    at java.lang.invoke.LambdaForm$MH/0x0000000800769840.invoke (LambdaForm$MH)
    at java.lang.invoke.Invokers$Holder.invokeExact_MT (Invokers$Holder)

I increased the available memory for Maven by creating a .mvn/jvm.config file at the project root to increase the Java heap:

-Xmx2048m

I also tried with -Xmx3048m, but none of that helped. Removal of the last chapter makes it work again. Removing the last chapter and including the 2nd to last chapter 2 times also makes it fail. Using only the last chapter and removing all other chapters also works.

Is there anything else I can try to make it work again?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions