Why is this a re-release of CTFrame

Working with some CoreText code on iOS, and I'm confused why this is a CTFrame override. I confirmed that this is a re-release, but I'm confusing because it was created using the create method.

 for (NSValue *value in [self frameArray]) { CGRect column = [value CGRectValue]; CGMutablePathRef path = CGPathCreateMutable(); CGPathAddRect(path, NULL, column); CTFrameRef frame = CTFramesetterCreateFrame(bodyFramesetter, CFRangeMake(position, 0), path, NULL); CTFrameDraw(frame, context); position += CTFrameGetVisibleStringRange(frame).length; CGPathRelease(path); // ???: Why does this cause an overrelease? //CFRelease(frame); } 

Update

The code base is 3.2, and the crash does not occur in the first release. This happens "randomly" at some point when drawing the view. This loop, as you might guess, is in -drawRect: views. There is no multithreading in this application.

+7
objective-c core-text
source share
2 answers

It turns out that Jason was on the right track and that the problem went through an empty frameset to the CTFramesetterCreateFrame function, which then returned NULL.

+3
source share

This is because your drawRect: method is called at the end of the loop. This is why your application crashes.

So, your solution is to create a global reference to the CTFrame object and free this object only in dealloc and when creating another CTFrame object (and replacing your global reference).

0
source share

All Articles