この単純なコードがメモリリークを引き起こすことがある理由はわかりません(常にではありません)。
このコードはNSOperationにラップされ、NSOperationQueueキューで実行されます。この操作は、sourceNSAStringをトリミングしてサイズに合わせ、結果として他のスレッドに返します。
//sourceNSAString is a NSMutableAttributedString that will be set to nil elsewhere in another GCD queue.
CTFramesetterRef frameSetter = CTFramesetterCreateWithAttributedString((__bridge CFAttributedStringRef) sourceNSAString);
if (frameSetter) {
CFRange fitRange = {static_cast<CFIndex>(range.location), 0};
CFRange totalRange = {static_cast<CFIndex>(range.location), static_cast<CFIndex>(range.length)};
CGSize suggestedSize = CTFramesetterSuggestFrameSizeWithConstraints(frameSetter, totalRange, NULL, size, &fitRange);
CFRelease(frameSetter);
...... trim sourceNSAString to fit in fitRange
}
それは次の理由によるものです:1、sourceNSAStringを別のスレッドに返すべきではありませんか?または2、CTFramesetterCreateWithAttributedStringはバックグラウンドスレッドで使用できませんか?
何か案は?ありがとう!