You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by honyk <j....@email.cz> on 2012/02/25 09:46:58 UTC

Fop memory leak when processing SVG

Dear All,

I use FOP (1.0) for processing a simple two page FO file with one complex
SVG file on each page.

In my web app (bean) I instantiate the following Producer class once and
then I call its createPDF method several times. I get very quicky Heap Space
errors. In the NetBeans profiler I've noticed that each iteration leaves
couple of objects in the memory which are not relased even when the garbage
collector is triggered. 

All these objects are Batik related. Like Batik would be used for SVG
rendering, but not released at all at the end. I can send the profiler
snapshot if you like.

Or is there any mistake in my code which is causing this?

Jan


public class Producer {

    FopFactory fopFactory = FopFactory.newInstance();
    Transformer transformer =
TransformerFactory.newInstance().newTransformer();

    public Producer() throws Exception {
        fopFactory.setUserConfig(getFopConfig());
    }

    private Configuration getFopConfig() throws Exception {
        DefaultConfigurationBuilder cfgBuilder = new
DefaultConfigurationBuilder();
        return
cfgBuilder.build(this.getClass().getResourceAsStream(Settings.resourceBasePa
th + "config/fop.xml"));
    }

    public void createPDF(File foFile, File output) throws Exception {

        OutputStream out = new BufferedOutputStream(new
FileOutputStream(output));
        
        Fop fop = null;
        Result pdfResult = null;
        SAXSource source = null;
        
        try {
        
            fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);

            InputStream inputStream = new FileInputStream(foFile);
            Reader reader = new InputStreamReader(inputStream, "UTF-8");
            InputSource is = new InputSource(reader);
            source = new SAXSource(is);
            source.setXMLReader(XMLReaderFactory.createXMLReader());
            pdfResult = new SAXResult(fop.getDefaultHandler());
            transformer.transform(source, pdfResult);            

        } finally {
            out.close();
            fop = null;            
        }
    }

}


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org


Re: Fop memory leak when processing SVG

Posted by Rob Sargent <rs...@xmission.com>.
And what happens if you destroy/reconstruct the Producer?

On 02/25/2012 01:46 AM, honyk wrote:
> Dear All,
>
> I use FOP (1.0) for processing a simple two page FO file with one complex
> SVG file on each page.
>
> In my web app (bean) I instantiate the following Producer class once and
> then I call its createPDF method several times. I get very quicky Heap Space
> errors. In the NetBeans profiler I've noticed that each iteration leaves
> couple of objects in the memory which are not relased even when the garbage
> collector is triggered.
>
> All these objects are Batik related. Like Batik would be used for SVG
> rendering, but not released at all at the end. I can send the profiler
> snapshot if you like.
>
> Or is there any mistake in my code which is causing this?
>
> Jan
>
>
> public class Producer {
>
>      FopFactory fopFactory = FopFactory.newInstance();
>      Transformer transformer =
> TransformerFactory.newInstance().newTransformer();
>
>      public Producer() throws Exception {
>          fopFactory.setUserConfig(getFopConfig());
>      }
>
>      private Configuration getFopConfig() throws Exception {
>          DefaultConfigurationBuilder cfgBuilder = new
> DefaultConfigurationBuilder();
>          return
> cfgBuilder.build(this.getClass().getResourceAsStream(Settings.resourceBasePa
> th + "config/fop.xml"));
>      }
>
>      public void createPDF(File foFile, File output) throws Exception {
>
>          OutputStream out = new BufferedOutputStream(new
> FileOutputStream(output));
>
>          Fop fop = null;
>          Result pdfResult = null;
>          SAXSource source = null;
>
>          try {
>
>              fop = fopFactory.newFop(MimeConstants.MIME_PDF, out);
>
>              InputStream inputStream = new FileInputStream(foFile);
>              Reader reader = new InputStreamReader(inputStream, "UTF-8");
>              InputSource is = new InputSource(reader);
>              source = new SAXSource(is);
>              source.setXMLReader(XMLReaderFactory.createXMLReader());
>              pdfResult = new SAXResult(fop.getDefaultHandler());
>              transformer.transform(source, pdfResult);
>
>          } finally {
>              out.close();
>              fop = null;
>          }
>      }
>
> }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org