Naveen Shan
Naveen Shan

Reputation: 9192

Memory Leaks when calling some CTFunctions in iPhone

I write a function to calculate the end index of attributtedString in a rect,

But it seems some memory leak, Please help me to fix it.

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);

thanks in advance.

Upvotes: 3

Views: 696

Answers (3)

MoDJ
MoDJ

Reputation: 4425

I did some more investigation on a device and there does seem to be a leak in CoreText, see Memory usage grows with CTFontCreateWithName and CTFramesetterRef

Upvotes: 0

Dennis Pashkov
Dennis Pashkov

Reputation: 944

There is a special release for CGPathRef objects.

//CFRelease(path);
CGPathRelease(path);

Upvotes: 0

Cocoanetics
Cocoanetics

Reputation: 8247

There is no memory leak in the above example. As far as we can see you are releasing everything properly.

Upvotes: 1

Related Questions