0

I have a code snippet as below:

NSURL *fonturl = [NSURL fileURLWithPath:gdbPath];
CGDataProviderRef fontDataProvider = CGDataProviderCreateWithURL((__bridge CFURLRef)fonturl);
CGFontRef newFont = CGFontCreateWithDataProvider(fontDataProvider);
NSString *newFontName = CFBridgingRelease(CGFontCopyPostScriptName(newFont));
CGDataProviderRelease(fontDataProvider);
CFErrorRef fonterror;
CTFontManagerRegisterGraphicsFont(newFont, &fonterror);
CGFontRelease(newFont);

Here I get a memory leak when I worked with Xcode Instruments. I tried many times to get rid of this with several alternatives. But I could not escape from memory leaks.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
  • Which line exactly does it says is leaking? What kind of struct/object? There are 2 ZZCreate, and I saw the two ZZRelease, so it should be good. – Larme Sep 30 '14 at 13:31
  • @Larme : NSString *newFontName = CFBridgingRelease(CGFontCopyPostScriptName(newFont)); – Shaheer Palollathil Sep 30 '14 at 13:35
  • Are you using ARC or not? What do you do with `newFontName`? – rmaddy Sep 30 '14 at 15:48
  • @rmaddy: Yes, am using ARC. UIFont * finalFont = [UIFont fontWithName:newFontName size:fontSize]; – Shaheer Palollathil Oct 01 '14 at 04:15
  • It looks right. The ownership of the font name string should be passed to `newFontName` and ARC should release it when done. Are you seeing the leaks in the simulator or a real device? Try a real device if you aren't. – rmaddy Oct 01 '14 at 04:19

0 Answers0