I checked the mail archives, but I couldn't find anything similar.

We have code that generates a 12 page PDF document.  It seems that initally
everything is fine and the document is generated successfully.  However,
after generating a few documents this way, the app server that it's
executing in (Weblogic 6.1SP2 on Windows) begins using excessive amounts of
memory, e.g. around 700Mb!  (Taken from the windows task manager VM Size
column.)  Naturally, this hammers a box pretty badly, but once the document
is finally rendered and sent to the browser, the garbage collector cleans
everything up.  Our problem is that this basically shuts down the app
server, which is pretty bad, and occasionally causes OutOfMemory
errors/crashes it.  The following stack trace was taken from an
OutOfMemoryError where we were using iText v0.96:

java.lang.OutOfMemoryError
        at java.util.zip.Deflater.init(Native Method)
        at java.util.zip.Deflater.<init>(Deflater.java:92)
        at java.util.zip.Deflater.<init>(Deflater.java:109)
        at
java.util.zip.DeflaterOutputStream.<init>(DeflaterOutputStream.java:70)
        at com.lowagie.text.pdf.PdfStream.flateCompress(Unknown Source)
        at com.lowagie.text.pdf.PdfFormXObject.<init>(Unknown Source)
        at com.lowagie.text.pdf.PdfTemplate.getFormXObject(Unknown Source)
        at com.lowagie.text.pdf.PdfWriter.close(Unknown Source)
        at com.lowagie.text.pdf.PdfDocument.close(Unknown Source)
        at com.lowagie.text.Document.close(Unknown Source)
        at
com.workbrain.tool.renderer.bo.pdf.PdfShow.doGet(PdfShow.java:167)
        at
com.workbrain.tool.renderer.bo.pdf.PdfShow.doPost(PdfShow.java:38)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
...

I upgraded to version 1.0 in the hopes of correcting the problem, but it
still exists.  I did a thread dump on the app server when it went into the
Document.close (v1.0) method and got the following:
    "ExecuteThread: '7' for queue: 'default'" (TID:0x3192818,
sys_thread_t:0x11375ef8, state:MW, native ID:0x450) prio=5
        at com.lowagie.text.pdf.ByteBuffer.formatDouble(Unknown Source)
        at com.lowagie.text.pdf.ByteBuffer.formatDouble(Unknown Source)
        at com.lowagie.text.pdf.PdfNumber.<init>(Unknown Source)
        at com.lowagie.text.pdf.PdfNumber.<init>(Unknown Source)
        at com.lowagie.text.pdf.PdfRectangle.<init>(Unknown Source)
        at com.lowagie.text.pdf.PdfRectangle.<init>(Unknown Source)
        at com.lowagie.text.pdf.PdfFormXObject.<init>(Unknown Source)
        at com.lowagie.text.pdf.PdfTemplate.getFormXObject(Unknown Source)
        at com.lowagie.text.pdf.PdfWriter.addSharedObjectsToBody(Unknown
Source)
        at com.lowagie.text.pdf.PdfWriter.close(Unknown Source)
        at com.lowagie.text.pdf.PdfDocument.close(Unknown Source)
        at com.lowagie.text.Document.close(Unknown Source)
        at
com.workbrain.tool.renderer.bo.pdf.PdfShow.doGet(PdfShow.java:173)
        at
com.workbrain.tool.renderer.bo.pdf.PdfShow.doPost(PdfShow.java:38)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
...

The following code snippet executes within a servlet.  I know that the
memory is all used within the close method because I had added some
System.outs around the various calls and it always paused immediately after
printing the one before the close call and before the one after.

    Document document = new Document();
    document.setMargins(aProps.getIntProperty("reportLeftMargin", 0),
                        aProps.getIntProperty("reportLeftMargin", 0),
                        aProps.getIntProperty("reportTopMargin", 0),
                        aProps.getIntProperty("reportBottomMargin", 0)
                        );
    document.setPageSize(new Rectangle(
            aProps.getIntProperty("reportPageWidth", 0),
            aProps.getIntProperty("reportPageHeight", 0))
            );

    // *** Creating the report ***
    response.setHeader("Content-type", "application/pdf");
    response.setHeader("Content-Disposition", "inline;filename=Report.pdf");
    response.setHeader("Cache-Control", "must-revalidate, post-check=0,
pre-check=0");
    response.setHeader("Pragma", "public");
    // ********* OUTPUT *******
    ServletOutputStream out = null;
    PdfWriter writer = null;
    try {
        out = response.getOutputStream();
        writer = PdfWriter.getInstance(document, out);
        document.open();
        PdfContentByte cb = writer.getDirectContent();
        renderer.setContentByte(cb);
        renderer.doRendering(form, controls);
    } catch (Exception e) {
        if (logger.isEnabledFor(org.apache.log4j.Level.ERROR)) {
logger.error(e, e);}
        throw new ServletException(e);
    } finally {
        if (document != null) document.close();
        if (out != null) { out.flush(); out.close(); }
        if (writer != null) writer.close();
        if (renderer != null) renderer.close();
    }


Any help would be much appreciated.

Thanks in advance,
Greg Taylor.
Workbrain Inc.



-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps1
_______________________________________________
iText-questions mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/itext-questions

Reply via email to