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
Cocoa (API)
(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!
==Memory management== One feature of the Cocoa environment is its facility for managing dynamically allocated memory. [[Foundation Kit]]'s NSObject class, from which most classes, both vendor and user, are derived, implements a [[reference counting]] scheme for memory management. Objects that derive from the NSObject root class respond to a <code>retain</code> and a <code>release</code> message, and keep a retain count. A method titled <code>retainCount</code> exists, but contrary to its name, will usually not return the exact retain count of an object. It is mainly used for system-level purposes. Invoking it manually is not recommended by Apple. A newly allocated object created with <code>alloc</code> or <code>copy</code> has a retain count of one. Sending that object a <code>retain</code> message increments the retain count, while sending it a <code>release</code> message decrements the retain count. When an object's retain count reaches zero, it is deallocated by a procedure similar to a C++ ''destructor''. <code>dealloc</code> is not guaranteed to be invoked. Starting with Objective-C 2.0, the Objective-C runtime implemented an optional [[Objective-C#Garbage collection|garbage collector]], which is now obsolete and deprecated in favor of [[Automatic Reference Counting]] (ARC). In this model, the runtime turned Cocoa [[reference counting]] operations such as "retain" and "release" into [[no-op]]s. The garbage collector does not exist on the [[iOS]] implementation of Objective-C 2.0. Garbage collection in Objective-C ran on a low-priority background thread, and can halt on Cocoa's user events, with the intention of keeping the user experience responsive. The legacy garbage collector is still available on Mac OS X version 10.13, but no Apple-provided applications use it. In 2011, the [[LLVM]] compiler introduced [[Automatic Reference Counting]] (ARC), which replaces the conventional garbage collector by performing static analysis of Objective-C source code and inserting retain and release messages as necessary.
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)