From: Duncan M. <du...@on...> - 2009-07-06 23:10:49
|
Sorry, yet more woes from me. I've pretty much given up being able to write PDF directly from RubyCocoa without leaking badly (CGImageSourceRefs, can't live with 'em, can't dispose of 'em), and as my customers are passing 200 pages of 300 DPI images for me to write to a PDF, this is a big problem. So I've moved the PDF rendering into an Objective-C class, and then load and use that class from my RubyCocoa class, passing in NSImageRepresentations. But I still leak. In the end it boils down to the following test #!/usr/bin/env ruby require 'test/unit' require 'osx/cocoa' include OSX OSX::NSApplication.sharedApplication NSBundle.bundleWithPath('build/Debug/VelOCRaptorShared.bundle').load class QuartzPDFWriterTest < Test::Unit::TestCase def test_NSImage 1.upto(10000) do |i| p i image = NSImage.alloc.initWithContentsOfFile 'testdata/pot pourri/ blood.jpg' #ObjectSpace.garbage_collect end end end If I don't garbage collect, this code will run from the console until the process has consumed all available memory and started sucking disk. If I un-comment the garbage_collect, it sits happily at 30MB or so of real memory. As a Java guy I expected not to have to second-guess when GC would be a good idea, but here it seems that Ruby just doesn't try to GC in the hard loop. Is this due to the green threads, or am I missing something fundamental here? When does Ruby start a GC in normal code? Cheers Duncan |