The access of weak reference will change the dealloc time on iOS

IDE: VS 2015
Version: 8.3.91.1965
Target (If relevant): iOS
Description:
This is a new thread to replace the the old issue reported here: Question about Element's ARC which was thought to be fixed, but when I write something more, it comes back again.

Here’s the new test project and code snippet:
MemoryLeakTest2.zip (121.6 KB)

        /**
        Environment:
        iPad Mini4 physical device (x64 ARM) + Release mode
        */

        // Case 1:
        var a1 = createObj();
        __weak object b1 = a1;
        NSLog("before set nil: ");
        a1 = null;
        NSLog("after set nil: ");
        /**
        Case 1 Output:
        before set nil: 
        BigObject dealloc!!
        after set nil: 
        */

        // Case 2:
        var a2 = createObj();
        __weak object b2 = a2;
        NSLog("before set nil: "+b2);
        a2 = null;
        NSLog("after set nil: "+b2);
        /**
        Case 2 Output:
        before set nil: <BigObject: 0x134d04c80>
        after set nil: <BigObject: 0x134d04c80>
        BigObject dealloc!!
        */

I think this issue is still related to objc_retainAutoreleasedReturnValue and should be investigated more deeply. Because the Case 1 can only work under very specific condition (Optimize code + Physical x64 iOS device, no debug mode, no sim), but the equvalent objective-c code always behaves as expected under all conditions.

Let me just log this again. Last time i looked this looked unfixable with exception handling we emit but maybe I’ll find something new. For what it’s worth, an OSX testcase would be a lot easier to debug and fix, any chance you can make this fail on OSX too?

Thanks, logged as bugs://74930

I have a quick try on OSX and find the issue can be reproduced for both two cases in debug/release mode for 8.3.91.1965.

Here’s my test project:
MacApp1.zip (667.1 KB)

bugs://74930 got closed with status fixed.

This prints:


before set nil: 
BigObject dealloc!! 1
after set nil: 
before set nil: <__ConsoleApplication815_BigObject: 0x7fa96f507280>
BigObject dealloc!! 2
after set nil: (null)

In current (in release mode); I’m looking into why it debug just won’t work.