ipad - 为什么我无法在应用程序崩溃的情况下释放我的 CTFramesetter?

标签 ipad memory-management ios nsattributedstring core-text

我正在构建一个 iPad 应用程序,它从 NSAttributedString 渲染文本页面。我创建了一个像这样的框架 setter :

- (void)renderTextFromAttributedString:(NSAttributedString *)string
{
    CFAttributedStringRef attrString = (CFAttributedStringRef)string;
    framesetter = CTFramesetterCreateWithAttributedString(attrString);
    CFRelease(attrString);

...然后代码逐一添加新的页面 View ,并将框架 setter 指针传递给每个页面以渲染每个页面,直到没有剩余字符:

- (void)drawNewPage
{
    CTSinglePageView *newPage = [[CTSinglePageView alloc] initWithFrame:newFrame];
    newPage.delegate = self;
    [newPage renderWithFramesetter:framesetter fromIndex:currentIndex margins:self.margins];
    [self addSubview:newPage];
    [newPage release];
    currentPage ++;

...等等等等。现在这一切都很好,渲染页面并完美显示格式化文本。但是,在渲染过程结束时,我仍然有一个需要清除的 CTFramesetter,以便我可以构建下一组页面。但是,如果我这样做

    if(framesetter) CFRelease(framesetter);

在该过程结束时,CTFramesetter 被释放(显然)并且程序崩溃!但是...如果我不释放框架 setter ,我最终会出现相当大的内存泄漏,并且程序会退出。

为什么发布会导致崩溃?打开 NSZombieEnabled 后,我收到的错误消息是:

* -[NSConcreteAttributedString release]: message sent to deallocated instance 0xed20270

我们当然会非常感激所提供的任何帮助!我们目前正面临最后期限,如果我现在可以添加赏金,我会的! 任何给出好的答案的人都将在 2 天的窗口期过后获得奖励。 :-)

最佳答案

您确定要释放 attrString 吗?这看起来不对劲。我想知道这是否会导致稍后释放框架设置程序时崩溃。

关于ipad - 为什么我无法在应用程序崩溃的情况下释放我的 CTFramesetter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4268458/

相关文章:

iphone - 如何在 Xcode 中记录用户按下 UIbutton 的顺序

iphone - 在 iOS 中为核心数据项目计算时间戳

ios - 在 swift 中分配特定数量的内存 - iOS

c++ - 智能指针实现的隐式转换

ios - 如何使用 swift 将 PFFile 转换为 UIImage?

iphone - 从外部路径加载 TTF 字体

iphone - 交换 Root View Controller

c# - 在 C# 和 C++ 代码之间共享对象

ios - 在 SWRevealViewController 之前登录 View Controller

iphone - 在 iOS 本地化中使用符号链接(symbolic link)