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

Cause of iOS ARC over-release crash on XCode 6.4 optimised build?

以下方法由于 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 移动到 after while 循环,您将看到该循环有效。

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