From: Austin Ziegler Date: 2006-02-02T03:56:19+09:00 Subject: Re: PDF::Writer running out of memory On 01/02/06, Damphyr wrote: > I have a bunch of XML files containing specifications and I want to > create a PDF file with an overview of the description element from > those XML files. I parse the XML and convert it into a Spec object > than I create the PDF using some attributes. Now, the following code > runs out of memory at about 53 out of 87 of those specs. header and > footer add a line and a bit of text (it's actually code adapted from > the PDF::Writer Manual Techbook :) ) I have had someone else report this and provide me with a customized SimpleTable that drastically reduces the memory usage but drops some...recoverability; it does not surprise me that this is happening, but I have had no time to investigate exactly what can be done. It does not surprise me that this is happening, and there may be several ways to solve this. The problem is best shown with code: require 'transaction/simple' class Parent include Transaction::Simple attr_accessor :children def add_children(*children) children.each { |x| x.parent = self @children << x } end def initialize @children = [] end end class Child attr_accessor :parent end def show_ids(parent) puts <<-EOS self <#{parent.object_id}> [ #{parent.children.map do |el| el.parent.object_id end.join(', ') } ] EOS end a = Parent.new a.add_children Child.new ; nil show_ids(a) # self<24875792> [ 24875792 ] a.start_transaction ; nil a.add_children Child.new, Child.new ; nil show_ids(a) # self<24875792> [ 24875792, 24875792, 24875792 ] a.rewind_transaction ; nil a.add_children Child.new, Child.new ; nil show_ids(a) # self<24875792> [ 24852044, 24875792, 24875792 ] That last one is the source of the memory leak. It's also the source of a much more subtle bug in the making it impossible to set certain things "late" in the process. -austin -- Austin Ziegler * halostatue@gmail.com * Alternate: austin@halostatue.ca