I have
static __weak ExplorerController *_rootExplorer = nil;
and
_rootExplorer = self;
NSAssert(_rootExplorer == self, @"????");
which works.
In dealloc, I try to do this
bool b = _rootExplorer == self;
which is false, but the debugger clearly states both objects are the same and have the same physical address.
When I do
long n = (long) (_rootExplorer);
long n2 = (long) (self);
I get a very large number for n2 and zero for n. But _rootExplorer is not nil. However, if I do the same thing in other functions that is not dealloc, n and n2 are identical.
What’s wrong with my code? I’m trying to keep a weak reference to one of the navigation controllers in the stack, and during unwinding, I need to release resources but only the referenced controller is allowed to do it.
Apple’s ARC documentation says, “A weak reference is set to nil when there are no strong references to the object.” So, I don’t think there’s anything wrong with your code (…other than, in some sense, its location being after ARC has done its work).