내 코드에서 문제가 발생하는 메모리 누수가 있습니다. 이 라인에서 특히, 나는 EXC_BAD_ACCESS 받고 있어요 (코드 = 1) : 다음 코드에서CTLineRef에서 메모리 누수가 발생합니까?
CGFloat xStart = origin.x + CTLineGetOffsetForStringIndex(line, index, NULL);
:
- (CGRect)firstRectForNSRange:(NSRange)range;
{
NSInteger index = range.location;
NSArray *lines = (__bridge NSArray *) CTFrameGetLines(self.textFrame);
NSInteger linesCount = [lines count];
CFIndex paragraphSpacingOffset = (self.paragraphSpacing > 0) ? 1 : 0;
for (NSInteger i = 0 + paragraphSpacingOffset; i < (linesCount - paragraphSpacingOffset); i++)
{
CTLineRef line = (CTLineRef) CFBridgingRetain([lines objectAtIndex:i]);
CFRange lineRange = CTLineGetStringRange(line);
NSInteger localIndex = index - lineRange.location;
if (localIndex >= 0 && localIndex < lineRange.length)
{
NSInteger finalIndex = MIN(lineRange.location + lineRange.length, range.location + range.length);
CGPoint origin;
CTFrameGetLineOrigins(self.textFrame, CFRangeMake(i, 0), &origin);
CGFloat xStart = origin.x + CTLineGetOffsetForStringIndex(line, index, NULL);
CGFloat xEnd = origin.x + CTLineGetOffsetForStringIndex(line, finalIndex, NULL);
CGFloat ascent, descent;
CTLineGetTypographicBounds(line, &ascent, &descent, NULL);
CFRelease(line);
return CGRectMake(xStart, origin.y - descent, xEnd - xStart, ascent + descent);
}
else
{
CFRelease(line);
}
}
return CGRectNull;
}
내가 확인 한대로 메모리 누수의 거의 확실 해요 코드를 철저히. 코어 Foundation 객체 line
을 위의 방법으로 잘못 관리하는 방법을 알 수 있습니까? line
이 (가) CTLineGetOffsetForStringIndex
(으)로 다시 전송 될 때 문제가 발생합니까?
감사합니다. 롭, 평생만큼 생명의 은인입니다. –