As far as I know, when strongOne is deallocated, the weak reference to
the same object should be updated to nil.
That's right. But you're not deallocating the object when you set strongOne
to nil, you're just changing the pointer. ARC probably calls autorelease
on the object strongOne
points to, so the object won't actually be deallocated until later, when the autorelease pool is drained.
Why does that only happen in case 2?
Looks like ARC sends release
in that case, so the object is deallocated and your weak reference is updated right away.
Or, it might be that the compiler notices that you never use strongOne
before setting it to nil, except to assign it to a weak pointer, and so decides not to allocate the object in the first place. Step through that code and see if strongOne
ever gets a non-nil value.