The reality is that to produce the simplest of the PDFs you need a lot of things going on. It would be interesting to compare the memory footprint with other libraries of similar capabilities.
Paulo ----- Original Message ----- From: "Chad Loder" <[EMAIL PROTECTED]> To: "Post all your questions about iText here" <[email protected]> Sent: Saturday, June 09, 2007 1:08 AM Subject: Re: [iText-questions] High memory allocation with PdfPTable > On Fri, Jun 08, 2007 at 05:31:19PM +0100, Paulo Soares wrote: >> That's the problem of using tools without understanding them. Most GC >> strategies only release memory when it's full. If you only had 128M the >> GC would kick in earlier than with 256M. What I mean is that summing the >> memory taken by all the temporary objects, many of which go out of scope >> before others are created, is not the same as the memory needed to run a >> program. > > Paulo, > > I think you misunderstand the issue. Let's say you have a 128mb Java > heap. If, during processing, you have to use 129mb of heap all at > once, then GC will not help you. Furthermore, even if many of these > objects are temporary, creating and collecting lots of garbage is NOT > cheap. > > The attitude of "Oh, it's Java, I can create millions of temporary > objects and there will be no problem" is dangerous. There is no > substitute for efficient design. > > c > >> > -----Original Message----- >> > From: [EMAIL PROTECTED] >> > [mailto:[EMAIL PROTECTED] On >> > Behalf Of Chad Loder >> > Sent: Friday, June 08, 2007 5:51 PM >> > To: Post all your questions about iText here >> > Subject: Re: [iText-questions] High memory allocation with PdfPTable >> > >> > Paulo, >> > >> > You're kidding, right? What if the Java heap is only 128mb? >> > >> > c >> > >> > On Fri, Jun 08, 2007 at 03:41:58PM +0100, Paulo Soares wrote: >> > > What's the problem? The GC takes care of that. >> > > >> > > Paulo >> > > >> > > > -----Original Message----- >> > > > From: [EMAIL PROTECTED] >> > > > [mailto:[EMAIL PROTECTED] On >> > > > Behalf Of greggan1 >> > > > Sent: Friday, June 08, 2007 9:17 AM >> > > > To: [email protected] >> > > > Subject: [iText-questions] High memory allocation with PdfPTable >> > > > >> > > > >> > > > Hi >> > > > >> > > > I have tested your >> > > > http://itextdocs.lowagie.com/tutorial/objects/tables/pdfptable >> > > > /index.html#memory >> > > > and analyzed the memory allocation during the build with >> > NuMega from >> > > > Compuware. The result shows that 205 MB are used and about >> > > > 575 thousand >> > > > objects are temporarily created for the result, a pdf with a >> > > > size of 53kb. >> > > > The method BidiLine() used about 182 MB of memory. >> > > > >> > > > >> > > > >> > > > I then tried the older Table class and did the same loop with >> > > > the result >> > > > that 22 MB of memory were allocated and 610 thousand >> > objects created. >> > > > >> > > > >> > > > I'm using itext-2.0.0.jar. >> > > > >> > > > >> > > > Should it be like this? Or is it a bug in PdfPTable? Or >> > > > shouldn't itext be >> > > > used as a server side solution? I'm planning to use this on a >> > > > web site with >> > > > many users creating pdf's but it will make the server running >> > > > very slow. The >> > > > server must garbage collect immediately after a pdf is created. >> > > > >> > > > Temporary Bytes including Children: 210,014,040 Bytes >> > > > Temporary Objects including Children: 590,701 >> > > > >> > > > PdfPTable >> > > > Size of PDF: 53 kb >> > > > public void fragmentTable() >> > > > { >> > > > System.out.println("FragmentTable"); >> > > > int fragmentsize = 50; >> > > > // step1 >> > > > Document document = new >> > > > Document(PageSize.A4.rotate(), 10, 10, 10, >> > > > 10); >> > > > try { >> > > > // step2 >> > > > PdfWriter.getInstance(document, >> > > > new >> > > > FileOutputStream("FragmentTable.pdf")); >> > > > // step3 >> > > > document.open(); >> > > > // step4 >> > > > >> > > > PdfPTable table = new PdfPTable(2); >> > > > table.setWidthPercentage(100f); >> > > > >> > > > PdfPCell cell; >> > > > for (int row = 1; row <= 2000; row++) { >> > > > if (row % fragmentsize == 0) { >> > > > document.add(table); >> > > > table.deleteBodyRows(); >> > > > table.setSkipFirstHeader(true); >> > > > } >> > > > cell = new PdfPCell(new >> > > > Paragraph(String.valueOf(row))); >> > > > table.addCell(cell); >> > > > cell = new PdfPCell(new >> > > > Paragraph("Hello World")); >> > > > table.addCell(cell); >> > > > } >> > > > document.add(table); >> > > > } catch (Exception de) { >> > > > de.printStackTrace(); >> > > > } >> > > > // step5 >> > > > document.close(); >> > > > } >> > > > Temporary Bytes including Children: 205,371,200 Bytes >> > > > Temporary Objects including Children: 575,385 >> > > > >> > > > >> > > > >> > > > The memory allocation is the same if you skip the part with " >> > > > if (row % >> > > > fragmentsize == 0) { ...... >> > > > >> > > > >> > > > >> > > > Method: BidiLine.BidiLine() >> > > > Package: com.lowagie.text.pdf >> > > > View Call Graph >> > > > View Source Code >> > > > Execution Count: 8,040 >> > > > Temporary Bytes: 182,797,440 Bytes >> > > > Temporary Objects: 80,400 >> > > > >> > > > >> > > > >> > > > >> > > > >> > > > Table >> > > > >> > > > Size of PDF: 68 kb >> > > > public void oldFragmentTable() >> > > > { >> > > > System.out.println("FragmentTable2"); >> > > > int fragmentsize = 50; >> > > > // step1 >> > > > Document document = new >> > > > Document(PageSize.A4.rotate(), 10, >> > > > 10, 10, 10); >> > > > try { >> > > > // step2 >> > > > PdfWriter.getInstance(document, >> > > > new >> > > > FileOutputStream("FragmentTable2.pdf")); >> > > > // step3 >> > > > document.open(); >> > > > // step4 >> > > > >> > > > Table table = new Table(2); >> > > > table.setWidth(100f); >> > > > >> > > > Cell cell; >> > > > for (int row = 1; row <= 2000; row++) { >> > > > cell = new >> > Cell(String.valueOf(row)); >> > > > table.addCell(cell); >> > > > cell = new Cell("Hello World"); >> > > > table.addCell(cell); >> > > > } >> > > > document.add(table); >> > > > } catch (Exception de) { >> > > > de.printStackTrace(); >> > > > } >> > > > // step5 >> > > > document.close(); >> > > > } >> > > > Temporary Bytes including Children: 22,476,600 Bytes >> > > > Temporary Objects including Children: 610,873 >> > > > >> > > > >> > > > >> > > > Method: PdfDocument.add(com.lowagie.text.pdf.PdfTable, boolean) >> > > > Package: com.lowagie.text.pdf >> > > > >> > > > View Call Graph >> > > > View Source Code >> > > > Temporary Bytes: 6,608,088 Bytes >> > > > Temporary Objects: 191,496 >> > > > >> > > > //greggan ------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/ _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/
