Memory leak when calling some CTFunctions on iPhone

I am writing a function to calculate the final attributtedString index in rect,

But there seems to be some kind of memory leak, Please help me fix this.

CTFramesetterRef framesetter = CTFramesetterCreateWithAttributedString((CFAttributedStringRef)attributtedString);

CGMutablePathRef path = CGPathCreateMutable();
CGPathAddRect(path, NULL, rect);

CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(currentIndex, 0), path, NULL);

CFRange frameRange = CTFrameGetVisibleStringRange(frame);
endIndex += frameRange.length;

CFRelease(frame);
CFRelease(path);
CFRelease(framesetter);

early.

+3
source share
3 answers

In the above example, there is no memory leak. As far as we can see, you are releasing everything correctly.

+1
source

There is a special release for CGPathRef objects.

//CFRelease(path);
CGPathRelease(path);
0
source

I did some more research on the device and there seems to be a leak in CoreText, see Memory usage grows with CTFontCreateWithName and CTFramesetterRef

0
source

All Articles