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

ARC and autorelease


ARC does still use autorelease as a mechanism, but besides that, its compiled code is created to interoperate with no problem with MRC compiled code, thus autorelease is present.

Despite the fact that ARC does a good job handling the memory management for us, there is still a situation when you need to use autorelease. Sometimes, we create a large number of temporary objects and many of them are only used once. In this case, you might want to free up the memory used by them.

In order to dealloc those objects into the autorelease pool instead of waiting for them to be freed naturally, check out the following code sample in a non-ARC environment:

/*
  -------------------------------------------------------
  Non-ARC Environment with Memory Leaks
*/
@autoreleasepool 
{
  // No autorelease call here
   MyObject *obj = [[MyObject alloc] init];

   /* Since MyObject is never released its
     a leak even when the pool exits
  */
}

  /*
  -------------------------------------...