Question

I have seen a lot of questions on SO about this theme but they don't ask my case.

Analyzer is giving me this warning

incorrect decrement of the reference count of an object that is not owned at that point by the caller

but in my case the method in question is not generating or is not intended to return any context.

My method is like this:

@property (nonatomic, assign) CGContextRef ctx;

- (void)generatePDFWithSize:(CGSize)size andURL:(NSURL*)url {

  CGRect mediaBox = CGRectZero;
  mediaBox.size = tamanho;

  self.ctx = CGPDFContextCreateWithURL((__bridge CFURLRef)(URL), &mediaBox, NULL);

  for (int i=0; i<numberOfPages; i++) {
     CGPDFContextBeginPage(self.ctx, NULL);
     //... bla bla bla... generate page
     CGPDFContextEndPage(self.ctx);
  }

  CGContextRelease(self.ctx);
}

Analyzer is pointing to the last line.

How do I solve that?

Was it helpful?

Solution

You can keep a separate reference to your Context such as:

CGContextRef ctx = CGPDFContextCreateWithURL((__bridge CFURLRef)(URL), &mediaBox, NULL);
self.ctx = ctx;

Then you can release the context that you've created by calling:

CFRelease (ctx);

So you're not releasing the one that the compiler believes that self owns.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top