You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Sergei Ovchinnikov (JIRA)" <ji...@apache.org> on 2017/05/25 12:03:04 UTC

[jira] [Created] (PDFBOX-3808) Strange memory behavior on load PDDocument

Sergei Ovchinnikov created PDFBOX-3808:
------------------------------------------

             Summary: Strange memory behavior on load PDDocument
                 Key: PDFBOX-3808
                 URL: https://issues.apache.org/jira/browse/PDFBOX-3808
             Project: PDFBox
          Issue Type: Bug
            Reporter: Sergei Ovchinnikov
         Attachments: out2.pdf

 It takes ~600mb of memory after loading a single page document (with embeded fonts). Memory usage grows slightly with the increasing number of pages in the document. What's wrong with this PDF (I've not noticed strange patterns in PDF debugger) ?
{code}
    public static void main(String[] args) throws Exception {

        File in = new File("out2.pdf");
        File out = new File("out2_.pdf");
        if (!out.exists()) {
            out.createNewFile();
        }
        InputStream inputStream = null;
        OutputStream outputStream = null;
        System.out.println("start pdf 2 pdf");
        PDDocument doc = null;
        try {
            final long startTime = System.currentTimeMillis();
            inputStream = new BufferedInputStream(new FileInputStream(in));
            outputStream = new BufferedOutputStream(new FileOutputStream(out));

            System.out.println(MessageFormat.format("before loading totalMemory: {0}, free: {1}, max: {2}",
                    Runtime.getRuntime().totalMemory(),
                    Runtime.getRuntime().freeMemory(),
                    Runtime.getRuntime().maxMemory()));
            doc = PDDocument.load(inputStream, MemoryUsageSetting.setupTempFileOnly());
            System.out.println(MessageFormat.format("after loading totalMemory: {0}, free: {1}, max: {2}",
                    Runtime.getRuntime().totalMemory(),
                    Runtime.getRuntime().freeMemory(),
                    Runtime.getRuntime().maxMemory()));
            System.out.println("save");
            doc.save(outputStream);

            final long endTime = System.currentTimeMillis();
            System.out.println(MessageFormat.format("it takes {0,number,#.###} s to handle pdf 2 pdf ",
                    (endTime - startTime) / 1000.));
        } finally {
            try {
                if (doc != null) {
                    doc.close();
                }
            } finally {
                IOUtils.closeQuietly(inputStream);
                IOUtils.closeQuietly(outputStream);
            }
        }
        System.out.println("ok");

    }
{code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: dev-help@pdfbox.apache.org