Book Image

Objective-C Memory Management Essentials

Book Image

Objective-C Memory Management Essentials

Overview of this book

Table of Contents (18 chapters)
Objective-C Memory Management Essentials
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

An overview of Apple autoreleased classes


As it was said before, the Cocoa framework provides factory methods with autorelease for many of the basic classes such as NSString, NSArray, NSDictionary, NSColor, and NSDate. However, in the same time, there are some classes that deserve special attention.

NSRunLoop

While using NSRunLoop, at the beginning of every run loop, an autorelease pool will be created, and it will only be destroyed at the end of this run loop. To clarify, every temporary object created inside it will be deallocated at the end of the running iteration. It might not be beneficial if you are creating a large number of temporary objects inside the block; in this case, you should consider creating a new autorelease pool, as shown here:

The following code demonstrates what was discussed earlier:

id myPool = [NSAutoreleasePool new];
[myObject somethingThatCreatesManyObjects];
[myPool drain];

Notice that in order to end the autorelease pool, instead of sending a release message, we...