Uploaded image for project: 'FOP'
  1. FOP
  2. FOP-2505

SVG -> PDF throws java.lang.OutOfMemoryError: Java heap space

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0
    • None
    • image/svg
    • None
    • Windows 7 Enterprise

    Description

      This code:
      String fileName = "D:\\Users\\user\\Desktop\\12619527
      201193 OPT 2 COLORBOARD-Cell2.svg";
      File file = new File(fileName);
      String uri = file.toURI().toString();
      ByteArrayOutputStream output = new ByteArrayOutputStream();
      org.apache.fop.svg.PDFTranscoder pdf = new org.apache.fop.svg.PDFTranscoder();
      TranscoderInput from = new TranscoderInput(uri);
      TranscoderOutput to = new TranscoderOutput(output);
      pdf.transcode(from, to);
      byte[] buffer = output.toByteArray();

      is run with 4GB max heap size and generates this stack trace:
      Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
      at java.util.Arrays.copyOf(Arrays.java:3236)
      at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:118)
      at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.ja
      va:93)
      at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:153)
      at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:221)
      at sun.nio.cs.StreamEncoder.implWrite(StreamEncoder.java:282)
      at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:125)
      at java.io.OutputStreamWriter.write(OutputStreamWriter.java:207)
      at java.io.BufferedWriter.flushBuffer(BufferedWriter.java:129)
      at java.io.BufferedWriter.write(BufferedWriter.java:230)
      at java.io.Writer.write(Writer.java:157)
      at org.apache.fop.pdf.PDFStream.add(PDFStream.java:86)
      at org.apache.fop.pdf.PDFPattern.output(PDFPattern.java:271)
      at org.apache.fop.pdf.PDFDocument.outputIndirectObject(PDFDocument.java:
      1056)
      at org.apache.fop.pdf.PDFDocument.streamIndirectObject(PDFDocument.java:
      1021)
      at org.apache.fop.pdf.PDFDocument.output(PDFDocument.java:997)
      at org.apache.fop.svg.PDFGraphics2D.flushPDFDocument(PDFGraphics2D.java:
      480)
      at org.apache.fop.svg.PDFGraphics2D.createPattern(PDFGraphics2D.java:972
      )
      at org.apache.fop.svg.PDFGraphics2D.applyPaint(PDFGraphics2D.java:836)
      at org.apache.fop.svg.PDFGraphics2D.fill(PDFGraphics2D.java:1566)
      at org.apache.batik.gvt.FillShapePainter.paint(Unknown Source)
      at org.apache.batik.gvt.CompositeShapePainter.paint(Unknown Source)
      at org.apache.batik.gvt.ShapeNode.primitivePaint(Unknown Source)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(Unknown Source)
      at org.apache.batik.gvt.ShapeNode.paint(Unknown Source)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(Unknown Sou
      rce)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(Unknown Source)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(Unknown Sou
      rce)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(Unknown Source)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(Unknown Sou
      rce)
      at org.apache.batik.gvt.AbstractGraphicsNode.paint(Unknown Source)
      at org.apache.batik.gvt.CompositeGraphicsNode.primitivePaint(Unknown Sou
      rce)

      What’s particular about the content is that there is a data object reused a great amount of times and we’re suspecting the duplication and maybe lack of cleanup may be causing the large memory usage

      Attachments

        Activity

          People

            ssteiner Simon Steiner
            elisegev Eli Segev
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: