In objective-c, I know that a static variable (should?) retain its value for the lifetime of the program. But if it stores a pointer, does it count as strong in ARC? Can I depend on it and be assured that that instance will never go out of the heap once I assigned it to a static variable?
static ClassA* shared;
-(id)init
{
if (self=[super init]) {
shared=self;
}
return self;
}
Yes you can rely on it, once it’s assigned.
The Transitioning to ARC Release Notes state:
and then:
Given your
staticpointer references the object, it will remain “alive”. The scope of a pointer (whether global, a pointer on the stack or an instance variable) makes no difference.