代码行会导致仪器崩溃,但不会导致 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,每次执行循环时我将其存储在块中,然后在循环结束时释放它。什么会导致仪器崩溃?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因为你从来没有
alloc
、copy
或retain
块,所以你不应该释放它。运行静态分析器可能有助于解决此类错误。
since you never
alloc
,copy
, orretain
blocks you should not be releasing it.It may help for errors like this to run the static analyzer.