繁体   English   中英

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

[英]Line of code causes crash in instruments but not in Xcode

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,每次执行循环时,我将其存储在块中,然后在循环结束时释放它。 什么会导致仪器崩溃?

因为你永远alloccopy ,或retain块,你不应该释放它。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM