菜鸟教程小白 发表于 2022-12-13 06:07:31

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


                                            <p><p>我正在构建一个 iPad 应用程序,它从 NSAttributedString 呈现文本页面。我创建了一个这样的框架 setter :</p>

<pre><code>- (void)renderTextFromAttributedString:(NSAttributedString *)string
{
    CFAttributedStringRef attrString = (CFAttributedStringRef)string;
    framesetter = CTFramesetterCreateWithAttributedString(attrString);
    CFRelease(attrString);
</code></pre>

<p>...然后代码一个接一个地添加新的页面 View ,并将 framesetter 指针传递给每个页面以呈现每个页面,直到没有剩余字符:</p>

<pre><code>- (void)drawNewPage
{
    CTSinglePageView *newPage = [ initWithFrame:newFrame];
    newPage.delegate = self;
    ;
    ;
    ;
    currentPage ++;
</code></pre>

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

<pre><code>    if(framesetter) CFRelease(framesetter);
</code></pre>

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

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

<blockquote>
<p><em>*</em> -: message sent to deallocated instance 0xed20270</p>
</blockquote>

<p>任何提供的帮助当然都会受到极大的欢迎!我们目前正面临截止日期,如果我现在可以添加赏金,我会的! <strong>在 2 天的窗口期过后,任何回答好的人都将获得赏金奖励。</strong> :-)</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您确定要发布 attrString 吗?那看起来不对。我想知道这是否会导致稍后发布 framesetter 时崩溃。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ipad - 为什么我不能在应用程序崩溃的情况下释放我的 CTFramesetter?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/4268458/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/4268458/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ipad - 为什么我不能在应用程序崩溃的情况下释放我的 CTFramesetter?