- create AViewController a > Init gets called > Static pointer is set to a
- create AViewController b > Init gets called > Static pointer should be set to b. But the static pointer is not set to b! It's sets itself from a to nil!
Probably nothing other than actualSelf
has ownership of a
. Therefore, actualSelf = self;
during the initialization of b
causes a
to be fully released and thus deallocated. During the -dealloc
of a
, it sets actualSelf
to nil
. Apparently, this is coming after the assignment of actualSelf
to the new self
(object b
). (The precise order of operations of the ARC-supplied -release
call vis-a-vis the assignment of actualSelf
is unpredictable.)
The very fact that you are assigning actualSelf
to nil
in the -dealloc
method smells bad. It suggests that actualSelf
should be __weak
because if it's holding a strong reference to an object, then that object can't be deallocated.
At the very least, -dealloc
should test if actualSelf
equals self
before resetting it. But that will never be true so long as actualSelf
is a strong reference, since a strongly referenced object can't be deallocated.
This whole approach is deeply problematic. What are you really trying to accomplish?