How to release a CTFramesetter?
Asked Answered
W

1

1

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?

Wolfram answered 16/8, 2012 at 0:52 Comment(0)
A
0

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;
Aldus answered 16/8, 2012 at 4:37 Comment(4)
well, i checked and i have no failuresWolfram
@flybirdx is this reported as a leak? i know one of my apps which uses a ton of CT rendering - one problem i see is the glyph loading consumes alot of memory -- but this is not actually flagged as a leak.Aldus
no, it is not flagged, but i used heapshot analysis and it showed that this object is not releasing. the problem is that after many redraws, everything in my app becomes slow.Wolfram
@flybirdx sounds like we may have the same issue. i can open a ton of docs which use CT rendering, and CoreText allocates and never frees a bunch of stuff (e.g. glyph info). after the docs are closed, the app consumes a lot more memory than i think it should, and i have evaluated the heap extensively. i'm pretty obsessive about keeping my allocations straight -- i have written gone as far as writing error detection for leaks at termination (obviously, only for things i have control over).Aldus

© 2022 - 2024 — McMap. All rights reserved.