代码行会导致仪器崩溃,但不会导致 Xcode 崩溃

发布于 2024-08-11 20:03:56 字数 590 浏览 7 评论 0原文

BOOL continueLoop;
CGPoint thePoint;   

while(continueLoop != NO)
{
    continueLoop = NO;

    thePoint = [self generateRandomLocation];

    NSMutableArray *blocks = [self getBlocksForX:thePoint.x];

    for(BlueBlock *block in blocks)
    {
        if(block.getBlockLocationY == thePoint.y)
        {
            continueLoop = YES;
        }
    }
    [blocks release];
}

这会导致在仪器中运行时崩溃,但在 Xcode 中则不会。我缩小了问题范围,当这行代码处于循环中时,就会发生这种情况... NSMutableArray *blocks = [self getBlocksForX: thePoint.x];该方法返回一个 NSMutableArray,每次执行循环时我将其存储在块中,然后在循环结束时释放它。什么会导致仪器崩溃?

BOOL continueLoop;
CGPoint thePoint;   

while(continueLoop != NO)
{
    continueLoop = NO;

    thePoint = [self generateRandomLocation];

    NSMutableArray *blocks = [self getBlocksForX:thePoint.x];

    for(BlueBlock *block in blocks)
    {
        if(block.getBlockLocationY == thePoint.y)
        {
            continueLoop = YES;
        }
    }
    [blocks release];
}

This causes a crash when ran in instruments but not in Xcode. I narrowed the problem down, it happens when this line of code is in a loop... NSMutableArray *blocks = [self getBlocksForX: thePoint.x]; the method returns a NSMutableArray, I store it in blocks each time the loop is executed then at the end of the loop I release it. What would be causing instruments to crash?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

染柒℉ 2024-08-18 20:03:56

因为你从来没有 alloccopyretain 块,所以你不应该释放它。

运行静态分析器可能有助于解决此类错误。

since you never alloc, copy, or retain blocks you should not be releasing it.

It may help for errors like this to run the static analyzer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文