Skip Menu |

This queue is for tickets about the PDF-Create CPAN distribution.

Report information
The Basics
Id: 93412
Status: resolved
Priority: 0/
Queue: PDF-Create

People
Owner: Nobody in particular
Requestors: chris_jack [...] msn.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 1.08
Fixed in: (no value)



Subject: Memory leak
PDF-Create is leaking memory. I've used the example code from the CPAN synoposis as an example and wrapped it in a the Test::LeakTrace function no_leaks_ok to demonstrate this. This is in the file memory_leak.pl You can find the output from this in memory_leak.out There are various problems including things like circular references at line 47 in PDF/Create.pm I would request you either recode to avoid these problems (hence allowing the perl memory manager to clean up memory for itself) or add something to the close() function to go through the data structures at the end to remove the memory leaks. Regards Chris
Subject: memory_leak.out

Message body is not shown because it is too large.

Subject: memory_leak.pl
use PDF::Create; use Test::More; use Test::LeakTrace; no_leaks_ok { my $pdf = new PDF::Create('filename' => 'mypdf.pdf', 'Version' => 1.2, 'PageMode' => 'UseOutlines', 'Author' => 'Fabien Tassin', 'Title' => 'My title', ); my $root = $pdf->new_page('MediaBox' => [ 0, 0, 612, 792 ]); # Add a page which inherits its attributes from $root my $page = $root->new_page; # Prepare 2 fonts my $f1 = $pdf->font('Subtype' => 'Type1', 'Encoding' => 'WinAnsiEncoding', 'BaseFont' => 'Helvetica'); my $f2 = $pdf->font('Subtype' => 'Type1', 'Encoding' => 'WinAnsiEncoding', 'BaseFont' => 'Helvetica-Bold'); # Prepare a Table of Content my $toc = $pdf->new_outline('Title' => 'Document', 'Destination' => $page); $toc->new_outline('Title' => 'Section 1'); my $s2 = $toc->new_outline('Title' => 'Section 2', 'Status' => 'closed'); $s2->new_outline('Title' => 'Subsection 1'); $page->stringc($f2, 40, 306, 426, "PDF::Create"); $page->stringc($f1, 20, 306, 396, "version $PDF::Create::VERSION"); # Add another page my $page2 = $root->new_page; $page2->line(0, 0, 612, 792); $page2->line(0, 792, 612, 0); $toc->new_outline('Title' => 'Section 3'); $pdf->new_outline('Title' => 'Summary'); # Add something to the first page $page->stringc($f1, 20, 306, 300, 'by Fabien Tassin <fta@oleane.net>'); # Add the missing PDF objects and a the footer then close the file $pdf->close; } "memory_leaks.pl found problems";
From: chris_jack [...] msn.com
Just as an additional thought on this: probably the easiest way to solve this would be to use weaken from the Scalar::Util module to keep the existing circular references but allow them to free the memory when the object is deleted/undef'fed at the end. More information can be found at http://perldoc.perl.org/perlref.html about 2/3rds of the way down Apologies for not having time to do this myself at the moment and I understand not having time is not a unique problem to myself.
thanks for the report and the test case! The fix will be included in the next release.