Why is this an over-release of CTFrame
Asked Answered
V

2

7

Working with some CoreText code on iOS and I am confused as to why this is an overrelease of the CTFrame. I have confirmed it is an over-release but I am baffled because it is created with a 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 on the first release. It occurs "randomly" at some point while drawing the view. This loop, as you can probably guess is in the -drawRect: of the view. There is no multi-threading in this application.

Venicevenin answered 26/7, 2010 at 21:41 Comment(2)
Just a thought: have you tried reversing the order of the two releases?Blandishment
Are you absolutely positive that frame is not NULL at that point? Does the over-release happen the first time through the loop, last time, consistently or randomly? That definitely seems like a bug provided everything else in your code is sane. I will try to reproduce it here. Are you on iOS 3.2 or 4?Expiation
V
3

Turns out that Jason was on the right track and that the issue was passing in a empty framesetter to the CTFramesetterCreateFrame function which then returned NULL.

Venicevenin answered 4/8, 2010 at 1:53 Comment(1)
in my case, the CTFramesetterRef is not empty, but it still comes back with an empty CTFrameRef. Furthermore, I only notice that behavior on the iOS simulators 4.0 & 4.1. On 4.2 & 4.3, this code works fine. Any ideas?Glendaglenden
I
0

That's because your drawRect: method gets called in the end of run loop. That's why your app crashes randomly.

So your solution is to create global link to CTFrame object and release that object only in dealloc and when you're creating other CTFrame object (and replacing your global link).

Impotent answered 18/4, 2013 at 16:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.