Search code examples
objective-cioscore-graphicscore-text

How to release a CTFramesetter?


I am using CoreText in my app and i have a really huge leak but i cant fnd out why it happens. so here is the snippet of my code:

 _framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)_mAttributedString);

CFDictionaryRef frameOptionsDictionary = (CFDictionaryRef)[self frameOptionsDictionary];

_frame = CTFramesetterCreateFrame(_framesetter,
                                CFRangeMake(0, _mAttributedString.length),
                                path,
                                frameOptionsDictionary);

CFRelease(_framesetter), _framesetter = NULL;

As you can see, i am releasing me CTFramesetter... but app leaks, and instruments show me that CTFramesetter causes that. So how should i release it?


Solution

  • 0) ensure there are no failures:

    assert(_mAttributedString);
    assert(0 == _framesetter);
    _framesetter = CTFramesetterCreateWithAttributedString(
                                 (CFAttributedStringRef)_mAttributedString);
    
    CFDictionaryRef frameOptionsDictionary =
                       (CFDictionaryRef)[self frameOptionsDictionary];
    
    assert(path);
    assert(0 == _frame);
    _frame = CTFramesetterCreateFrame(_framesetter,
                                    CFRangeMake(0, _mAttributedString.length),
                                    path,
                                    frameOptionsDictionary);
    
    CFRelease(_framesetter), _framesetter = NULL;