From: Duncan M. <du...@on...> - 2009-07-07 10:09:18
|
On 7 Jul 2009, at 00:01, Scott Thompson wrote: > Ok. If it's not the garbage collector, how about an autorelease > pool. Surround your code in the loop with a local autorelease pool > and see if there might be some objective c objects hanging around > longer that you want them to. I really appreciate you sticking around once again Scott. Before my original post I had tried a pool, and I had tried CFRelease, and I had tried GC - but it turns out that I hadn't tried a pool _and_ CFRelease _and_ GC in the same loop. It works! I can't claim to understand why this works (or why more sensible solutions don't), but I post it here for posterity. def test_dispose_CGImageSource # All of draining the pool, releasing the image and the GC are required if this is not to leak 1.upto(10000) do |i| p i pool = NSAutoreleasePool.new imageSource = CGImageSourceCreateWithURL(NSURL.fileURLWithPath('testdata/pot pourri/ blood.jpg'), nil) image = CGImageSourceCreateImageAtIndex(imageSource, 0, nil) CFRelease image # CFRelease imageSource - can't as will segfault pool.drain ObjectSpace.garbage_collect end end I suspect that the explicit GC is required here for whatever reason it is required in my other post re disposing NSImage - in a hard RubyCocoa loop the GC doesn't seem to be triggered. Thanks again for keeping me believing that there is a way! Duncan |