5

My application uses a quartz filter to convert images within a PDF document to black and white:

PDF Document *pdfDocument = [[PDFDocument alloc] initWithURL:[NSURL fileURLWithPath:@"/Users/dan/Desktop/test.pdf"]];

QuartzFilter *quartzFilter = [QuartzFilter quartzFilterWithURL:[[NSBundle mainBundle] URLForResource:@"Black & White" withExtension:@"qfilter"]];

NSDictionary *options = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:quartzFilter, nil] forKeys:[NSArray arrayWithObjects:@"QuartzFilter", nil]];

[pdfDocument writeToFile:@"/Users/dan/Desktop/testResault.pdf" withOptions:options];

Unfortunately writing the file to disk with the filter applied results in many memory leaks as you can see here: enter image description here

Is this a bug within the Quartz Framework or am I doing something wrong in the code above?

If you want you can download my test project here: http://www.file-upload.net/download-7293644/PDF---Quartz-Memory-Leak.zip.html

I am using ARC.

Daniel
  • 1,473
  • 3
  • 33
  • 63
  • I just ran your code and didn't get a leak. I'm on 10.8.2 running XCode 4.6 (4H127). Where did you find out that you can pass @"QuartzFilter" as an option key when writing the file, I didn't see that in the Docs? – Daniel Farrell Mar 07 '13 at 09:54
  • I'm running it on the same system with the same XCode version. Here is the documentation: https://developer.apple.com/library/mac/documentation/GraphicsImaging/Reference/QuartzFramework/Classes/PDFDocument_Class/Reference/Reference.html#//apple_ref/occ/instm/PDFDocument/writeToURL:withOptions: Did you press the button (pdfDocument writeToFile:withOptions:options) ? – Daniel Mar 07 '13 at 11:22
  • Sure, I read the source code so I understood it, and then ran it. There is no documentation regarding the key "QuartzFilter" on that page. – Daniel Farrell Mar 07 '13 at 12:49
  • Ah, right. There is nor documentation on that. I read about it somewhere in a blog. Can't remember where. Maybe it depends on the pdf file. Try this test file: https://www.dropbox.com/s/07oq3njqail2axb/test.pdf I tried it on different Macs even with 10.7 Lion. It always leaks. – Daniel Mar 07 '13 at 14:47
  • Sorry, I didn't realise the Leak instrument updated every 10s. Indeed it does leak (I take my original comment back). Could there be a bug in your Quartz Filter (Black and White) file? The bug seems to happen when creating a ColorSpace. Have you tried testing with a filter that is known to be good and see if it still leaks? – Daniel Farrell Mar 07 '13 at 15:38
  • Looks like it really depends on the file and the filter. But I couldn't create a filter without the problem. I create the Filters using the ColorSync utility. It's not only ColorSpace. I fear its a bug within the framework, so there is nothing I can do about it right now :( – Daniel Mar 07 '13 at 16:33
  • If you have eliminated the possibility of it being a bad filter, maybe there are some additional options you need to pass when writing the file. The other possibility is that you are using undocumented APIs by passing the "QuatrzFilter" option. My final suggestion is that you try and apply the filter manually using the Quatrz C API. – Daniel Farrell Mar 08 '13 at 00:28
  • I'll have to figure out how to apply a filter using the Quatrz C API first. Is it even possible? If I succeed, I'll report. – Daniel Mar 10 '13 at 11:50
  • Are you using arc http://stackoverflow.com/questions/7874342/what-is-the-difference-between-objective-c-automatic-reference-counting-and-garb ? – Mehdi Karamosly Mar 14 '13 at 20:34
  • Yes I do (see above), why? – Daniel Mar 14 '13 at 20:43

0 Answers0