gpt4 book ai didi

ios - XCode 6.4 优化版本上 iOS ARC 过度发布崩溃的原因?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:58:14 25 4
gpt4 key购买 nike

以下方法由于 inputLower 的早期 ARC 发布而崩溃,即使在范围内仍然存在强 ptr。这是使用 XCode 6.4 为 ARM64 构建,只有在使用 -Os 优化时才会崩溃。这是 ARC 错误,还是我犯了某种 ARC 逻辑错误?

void crasher(NSString * input) {
NSString * inputLower = [input lowercaseString]; // should be strong ptr
NSString * inputLower2 = inputLower; // should be a 2nd, independent strong ptr
int i = 1;
while (i < 10) {
inputLower2 = [NSString stringWithFormat:@"%@%d", inputLower, i++];
// ERROR: inputLower is released here, so the next iteration will crash
NSLog(@"%@", inputLower2);
}
}

只需添加一个副本就可以避免崩溃,但我已经详细阅读了 ARC 规则,我认为这不是必需的:

NSString * inputLower2 = [inputLower copy];

如果这不是我的错,我会向 Apple 提交错误。

最佳答案

我以前见过这种事。这与其说是一个 ARC 问题,不如说是一个优化问题,尤其是 NSLog 引发了它。在这种情况下,导致问题的是 while 循环内的 NSLog;正在优化某些东西。如果将 NSLog 移动到 while 循环的之后,您将看到该循环有效。

此外,我无法在 Xcode 7 中重现崩溃(这就是为什么我花了这么长时间才重现它;我不得不专门切换到 Xcode 6.4)。这表明 Apple 员工确实知道这一点。

关于ios - XCode 6.4 优化版本上 iOS ARC 过度发布崩溃的原因?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31496488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com