在跟踪换行符的方法中频繁地, for a NSTextView visibleRect
,我正在分配内存NSGlyph to use NS布局管理器 getGlyphs:range:
.
我应该/可以找出这应该有多少内存,因为我有范围的参考(不影响布局),而且,应该进行什么样的清理——运行ARC ?
代码(在主队列上运行):
NSLayoutManager *lm = [self.textView layoutManager];
NSTextContainer *tc = [self.textView textContainer];
NSRect vRect = [self.textView visibleRect];
NSRange visibleRange = [lm glyphRangeForBoundingRectWithoutAdditionalLayout:vRect inTextContainer:tc];
NSUInteger vRangeLoc = visibleRange.location;
NSUInteger numberOfLines;
NSUInteger index;
NSGlyph glyphArray[5000]; // <--- memory assigned here
NSUInteger numberOfGlyphs = [lm getGlyphs:glyphArray range:visibleRange];
NSRange lineRange;
NSMutableIndexSet *idxset = [NSMutableIndexSet indexSet];
for (numberOfLines = 0, index = 0; index < numberOfGlyphs; numberOfLines++) {
(void)[lm lineFragmentRectForGlyphAtIndex:index effectiveRange:&lineRange withoutAdditionalLayout:YES];
[idxset addIndex:lineRange.location + vRangeLoc];
index = NSMaxRange(lineRange);
}
self.currentLinesIndexSet = idxset;
随着NSGlyph glyphs[5000]
符号,您正在堆栈上分配内存。但它只需要保存 5000 个字形visibleRange.length + 1
glyphs:
字形数组
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)