[ 
https://issues.apache.org/jira/browse/PDFBOX-3376?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Andreas Lehmkühler updated PDFBOX-3376:
---------------------------------------
    Description: 
PDFBox PDDocument still uses memory after destruction. This causes, 
surprisingly, memory leaks in Java. Sample code:
{code}
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Vector;

import org.apache.pdfbox.pdmodel.PDDocument;

//javac -cp pdfbox.jar:commons-logging.jar Mrg.java
//java -cp pdfbox.jar:commons-logging.jar:. Mrg *pdf

public class Mrg
{
        public static void main(String[] args) throws Exception
        {
                Runtime instance = Runtime.getRuntime();
                System.err.println("Start: "+instance.totalMemory());

                List <PDDocument> infiles = new Vector<PDDocument>();
                String outname = "Output.pdf";
                for(int i=0; i<args.length; i++)
                        infiles.add(PDDocument.load(new File (args[i])));
                PDDocument result = new PDDocument();
                for (PDDocument input : infiles)
                {
                        int inpages = input.getNumberOfPages();                 
                
                        for (int i=0; i<inpages; ++i)
                                result.addPage(input.getPage(i));
                }
                try     {
                        result.save(outname);
                } catch (IOException e) {
                        System.err.println(e.getMessage());
                        System.exit(1);
                }
                result.close();
                Thread.currentThread().sleep(1000);
                System.err.println("All open: "+instance.totalMemory());
                for (PDDocument i : infiles)
                        i.close();
                Thread.currentThread().sleep(1000);
                System.err.println("All closed: "+instance.totalMemory());
                (new java.util.Scanner(System.in)).nextLine();
                System.err.println("Finish: "+instance.totalMemory());
        }
}
{code}
Mine output:
>Start: 125829120
>All open: 277872640
>All closed: 277872640
>rthrth
>Finish: 277872640

The same happens with my main program (I was blaming SwingWorker): 
https://github.com/Yanpas/PdfMerger

  was:
PDFBox PDDocument still uses memory after destruction. This causes, 
surprisingly, memory leaks in Java. Sample code:

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Vector;

import org.apache.pdfbox.pdmodel.PDDocument;

//javac -cp pdfbox.jar:commons-logging.jar Mrg.java
//java -cp pdfbox.jar:commons-logging.jar:. Mrg *pdf

public class Mrg
{
        public static void main(String[] args) throws Exception
        {
                Runtime instance = Runtime.getRuntime();
                System.err.println("Start: "+instance.totalMemory());

                List <PDDocument> infiles = new Vector<PDDocument>();
                String outname = "Output.pdf";
                for(int i=0; i<args.length; i++)
                        infiles.add(PDDocument.load(new File (args[i])));
                PDDocument result = new PDDocument();
                for (PDDocument input : infiles)
                {
                        int inpages = input.getNumberOfPages();                 
                
                        for (int i=0; i<inpages; ++i)
                                result.addPage(input.getPage(i));
                }
                try     {
                        result.save(outname);
                } catch (IOException e) {
                        System.err.println(e.getMessage());
                        System.exit(1);
                }
                result.close();
                Thread.currentThread().sleep(1000);
                System.err.println("All open: "+instance.totalMemory());
                for (PDDocument i : infiles)
                        i.close();
                Thread.currentThread().sleep(1000);
                System.err.println("All closed: "+instance.totalMemory());
                (new java.util.Scanner(System.in)).nextLine();
                System.err.println("Finish: "+instance.totalMemory());
        }
}

Mine output:
>Start: 125829120
>All open: 277872640
>All closed: 277872640
>rthrth
>Finish: 277872640

The same happens with my main program (I was blaming SwingWorker): 
https://github.com/Yanpas/PdfMerger


> Memory leak in PDDcoument.close method
> --------------------------------------
>
>                 Key: PDFBOX-3376
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-3376
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 2.0.1
>            Reporter: Yan
>
> PDFBox PDDocument still uses memory after destruction. This causes, 
> surprisingly, memory leaks in Java. Sample code:
> {code}
> import java.io.File;
> import java.io.IOException;
> import java.util.List;
> import java.util.Vector;
> import org.apache.pdfbox.pdmodel.PDDocument;
> //javac -cp pdfbox.jar:commons-logging.jar Mrg.java
> //java -cp pdfbox.jar:commons-logging.jar:. Mrg *pdf
> public class Mrg
> {
>       public static void main(String[] args) throws Exception
>       {
>               Runtime instance = Runtime.getRuntime();
>               System.err.println("Start: "+instance.totalMemory());
>               List <PDDocument> infiles = new Vector<PDDocument>();
>               String outname = "Output.pdf";
>               for(int i=0; i<args.length; i++)
>                       infiles.add(PDDocument.load(new File (args[i])));
>               PDDocument result = new PDDocument();
>               for (PDDocument input : infiles)
>               {
>                       int inpages = input.getNumberOfPages();                 
>                 
>                       for (int i=0; i<inpages; ++i)
>                               result.addPage(input.getPage(i));
>               }
>               try     {
>                       result.save(outname);
>               } catch (IOException e) {
>                       System.err.println(e.getMessage());
>                       System.exit(1);
>               }
>               result.close();
>               Thread.currentThread().sleep(1000);
>               System.err.println("All open: "+instance.totalMemory());
>               for (PDDocument i : infiles)
>                       i.close();
>               Thread.currentThread().sleep(1000);
>               System.err.println("All closed: "+instance.totalMemory());
>               (new java.util.Scanner(System.in)).nextLine();
>               System.err.println("Finish: "+instance.totalMemory());
>       }
> }
> {code}
> Mine output:
> >Start: 125829120
> >All open: 277872640
> >All closed: 277872640
> >rthrth
> >Finish: 277872640
> The same happens with my main program (I was blaming SwingWorker): 
> https://github.com/Yanpas/PdfMerger



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to