prawnpdf/prawn — pull request #430 by kennethkalmer (2012-12-12 22:23:31+00:00)
Title: Table memory leak - Fixes 424

This is a fix for the memory leak reported in #424.

It boils down to https://github.com/prawnpdf/prawn/blob/master/lib/prawn/table/cell/text.rb#L147 making use of a thread-local cache for character sizes of the current font. The Font objects don't implement #hash or #eql?, so different instances of the same font will end up creating different keys in the thread-local and thus growing the cache.

As the simplest fix, possibly only the first step, I've basically implemented a #hash method that takes the results of #inspect and hashes that, and then #eql? to check that the hashes match.

I have no idea at the moment what the impact would be on different font sizes. I think we're safe guarded because the font size is in the inspect string, thus for different sizes the #hash output would be unique.