From book Programming in Objective-C 2.0
Sending a release message does not necessarily destroy an object. When an object’'s reference count is decremented to 0, the object is destroyed. The system does this by sending the dealloc message to the object to free its memory.
If you need to hold onto an object to make sure it doesn’t get destroyed by someone else, you should retain it. Make sure to release the object when you’re done with it.
Release any objects that you have retained or have created using a copy, mutable-Copy, alloc, or new method.This includes properties that have the retain or copy attribute. You can override dealloc to release your instance variables at the time
your object is to be destroyed.
The autorelease pool provides for the automatic release of objects when the pool itself is drained.The system does this by sending a release message to each object in the pool for each time it was autoreleased. Each object in the autorelease pool whose reference count goes down to 0 is sent a dealloc message to destroy the object.
If you no longer need an object from within a method but need to return it, send it an autorelease message to mark it for later release.The autorelease message does not affect the reference count of the object.
When your application terminates, all the memory your objects take up is released, regardless of whether they were in the autorelease pool.
When you develop Cocoa or iOS applications, autorelease pools will be created and drained throughout execution of the program (this will happen each time an event occurs). In such cases, if you want to ensure that your object survives automatic deallocation when the autorelease pool is drained, you need to retain it.All objects that have a reference count greater than the number of autorelease messages they have been sent will survive the release of the pool.
Subscribe to:
Post Comments (Atom)
Post Code on Blogger
Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...
-
Explain There is not interrupt PIN for PCIe interrupt. When device wants to raise an interrupt, an interrupt message is sent to host via ...
-
Configure Space Addressing One of the major improvements the PCI Local Bus had over other I/O architectures was its configuration mechanism...
-
What is LMA and VMA Every loadable or allocatable output section has two addresses. The first is the VMA, or virtual memory address. This ...
No comments:
Post a Comment