ICEpdf
  1. ICEpdf
  2. PDF-293

Memory problems cause rendering as white rectangle

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.2
    • Fix Version/s: 5.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      Multiple environments, see Description

      Description

      For the attached file I've observed the following behavior:
      * Windows-based PC with 8 Gb RAM and Sun SDK 6
      - Adobe Reader consumes ~40 Mb RAM
      - IcePdf Viewer app consumes ~500 Mb RAM and displays the image only after a series of window switching and resizing
      - my application invoking Document.getPageImage() (to PNG) consumes ~ 1 Gb RAM during first conversion and the amount grows after each subsequent attempt, though I never made it fail totally
      * Windows-based PC with 2 Gb RAM and Sun SDK 6
      - my application consumes ~ 500 Mb RAM and converts the PDF file to an empty white rectangle in PNG. No exceptions are thrown, no warnings are displayed (or may be I don't know where to look for warnings)
      * Linux-based server with 1Gb RAM, 512 Mb available for the app, Sun SDK 6
      - the same white rectangle with no other visible symptoms

      The code is as follows (it's Scala not Java but I think it's understandable):

      System.setProperty("org.icepdf.core.scaleImages", "false")
      GraphicsRenderingHints.getDefault.reset
      val doc = new Document()
      doc.setByteArray(bytes.toArray, 0, bytes.length, "image.pdf") //bytes.toArray gives us a correct Java byte[] with the whole PDF file there
      val image = doc.getPageImage(0, GraphicsRenderingHints.SCREEN, Page.BOUNDARY_CROPBOX, 0f, 2.0f).asInstanceOf[RenderedImage]
      val pngStream = new ByteArrayOutputStream()
      ImageIO.write(image, "png", pngStream)
      repository.setImage(id, Some(pngStream.toByteArray)) //it stores the resulting stream somewhere, not very important for the case I guess
      pngStream.close

        Activity

        Hide
        Patrick Corless added a comment -

        The Image in question is quite large requiring quite a bit of memory just to create it. Couple things to keep in mind.

        • when the Document load is complete, call document.dispose() to clean up any resources.
        • once you're down with the image object call image.flush() to free up some more memory.
        • consider doing a scaled image capture to reduce memory.
        • set the system property -Dorg.icepdf.core.scaleImages=false which should save a little memory during the initial page load.
        Show
        Patrick Corless added a comment - The Image in question is quite large requiring quite a bit of memory just to create it. Couple things to keep in mind. when the Document load is complete, call document.dispose() to clean up any resources. once you're down with the image object call image.flush() to free up some more memory. consider doing a scaled image capture to reduce memory. set the system property -Dorg.icepdf.core.scaleImages=false which should save a little memory during the initial page load.
        Hide
        Patrick Corless added a comment -

        This will be a good test for soon to come image processing optimizations.

        Show
        Patrick Corless added a comment - This will be a good test for soon to come image processing optimizations.
        Hide
        Patrick Corless added a comment -

        The imaging and memory model for 5.0 has been significantly which I think helps with document. Closing issue for now, can be reopened if the client requests it.

        Show
        Patrick Corless added a comment - The imaging and memory model for 5.0 has been significantly which I think helps with document. Closing issue for now, can be reopened if the client requests it.

          People

          • Assignee:
            Patrick Corless
            Reporter:
            Mikhail Kirillov
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: