What is the difference between strong
and weak
IBOutlets in the Xcode iOS 5.1 SDK?
I was previously using the 4.3 SDK, where strong IBOutlets did not exist. In addition, (auto)release is not available in the iOS 5.1 SDK.
Strong
means that as long as this property points to an object, that object will not be automatically released. In non-ARC it's a synonym for retain
Specifies that there is a strong (owning) relationship to the destination object.
Weak
instead, means that the object the property points to, is free to release but only if it sets the property to NULL. In ARC you use weak to ensure you do not own the object it points to
Specifies that there is a weak (non-owning) relationship to the destination object. If the destination object is deallocated, the property value is automatically set to nil.
Nonatomic
means that if multiple threads try to read or to change the property at once, badness can happen. Consequences are that there will be partially-written values or over-released objects = CRASH.
Take also a look here, at Apple's documents.
From there, examples are
@property (weak) IBOutlet MyView *viewContainerSubview;
@property (strong) IBOutlet MyOtherClass *topLevelObject;
Check also this to know more about strong
and weak
.
In ARC (Automatic Reference Counting) Strong
tells the compiler that the property-owner relationship is "strong". It is equivalent to retain
in the autorelease pool memory scheme. Apple has a article on transitioning to ARC here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With