Jump to content
  • Advertisement
Sign in to follow this  
GuyWithBeard

Cocoa/Objective-C memory leak when printing

This topic is 2950 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!

I have spend the last few days trying to find a memory leak in my code. Instruments (the Apple tool that detects memory leaks, among other things) reports leaked memory when printing from my app. I could not find the leaking code so I made a really small test app that just prints a view like this:

#import "PrintTestAppDelegate.h"

@implementation PrintTestAppDelegate

@synthesize window;
@synthesize testView;

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}

- (IBAction)doprint:(id)sender
{
NSPrintInfo* printInfo = [NSPrintInfo sharedPrintInfo];
[printInfo setVerticallyCentered:NO];
[printInfo setHorizontallyCentered:NO];
[printInfo setPaperName:@"A4"];
[printInfo setTopMargin:0.0];
[printInfo setBottomMargin:0.0];
[printInfo setLeftMargin:0.0];
[printInfo setRightMargin:0.0];
[printInfo setOrientation:NSLandscapeOrientation];
NSPrintOperation* op = [NSPrintOperation printOperationWithView:testView printInfo:printInfo];
[op runOperation];
}

@end


The view that is printed looks like:

#import "TestView.h"


@implementation TestView

- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
}
return self;
}

- (void)drawRect:(NSRect)dirtyRect
{
// Drawing code here.
[[NSColor redColor] set];
NSRectFill (dirtyRect);
}

- (BOOL)isFlipped { return YES; }

@end


Even this very simple code leaks memory according to Instruments. All I have to do is press the button that runs doprint: and select "Preview" in the print dialog to open up the document as a PDF. Boom, memory stars to leak. Now, if I remove all my printers from OSX and do the same (I can still do this since I don't actually print anything onto paper) I get no memory leaks.

Now, the interesting part is that Instruments reports the Responsible Library to be "CAPTUIKit". I did a search and it seems that CAPT stands for Canon Advanced Printing Technology, and indeed, I have a Canon printer. Could the memory leak actually be inside the printer driver?

Any ideas? Also, if you happen to know of any good techniques for locating a leak that shows up in Instruments, I'm all ears. Cheers!

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Now, the interesting part is that Instruments reports the Responsible Library to be "CAPTUIKit". I did a search and it seems that CAPT stands for Canon Advanced Printing Technology, and indeed, I have a Canon printer. Could the memory leak actually be inside the printer driver?


Yes it could. I seem to remember I had the same issue at one point with a library. I wouldn't worry about it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!