IDE: VS 2015
Target (If relevant): iOS
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.