Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Weak reference
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Objective-C 2.0=== In [[Objective-C]] 2.0, not only garbage collection, but also [[Reference counting|automatic reference counting]] will be affected by weak references. All variables and properties in the following example are weak. <syntaxhighlight lang=objc> @interface WeakRef : NSObject { __weak NSString *str1; __unsafe_unretained NSString *str2; } @property (nonatomic, weak) NSString *str3; @property (nonatomic, unsafe_unretained) NSString *str4; @end </syntaxhighlight> The difference between <code>weak</code> (<code>__weak</code>) and <code>unsafe_unretained</code> (<code>__unsafe_unretained</code>) is that when the object the variable pointed to is being deallocated, whether the value of the variable is going to be changed or not. <code>weak</code> ones will be updated to [[Null pointer|<code>nil</code>]] and the <code>unsafe_unretained</code> one will be left unchanged, as a [[dangling pointer]]. The <code>weak</code> references is added to Objective-C since [[Mac OS X Lion|Mac OS X 10.7 "Lion"]] and [[iOS 5]], together with [[Xcode]] 4.1 (4.2 for iOS), and only when using ARC. Older versions of Mac OS X, iOS, and GNUstep support only <code>unsafe_unretained</code> references as weak ones.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)