Manual Retain Release in iOS

Prashant Humney
1 min readFeb 7, 2018

Pre Automatic Reference Counting(ARC), memory management in iOS was troublesome. For example, if you are allocating memory to an object, then it is your responsibility to release the memory. Issues such as memory leak, dangling pointer creeps into your code.

To avoid such kind of issues, Apple came up with set of guidelines for developers while working in MRR or pre ARC.

  1. If you are making a call to either alloc/new or copy/mutableCopy then you have to make a subsequent call to release/autorelease.
  2. Adding to above point, if you are not making any alloc/copy calls, then you don’t have to release the object.
  3. Never use the retainCount method to count the number of strong dependencies to an object. For example, for immutable objects type like NSString,NSNumber the retain count value will be a big value number.
  4. You should not release memory of reference objects, like NSError *error which we usually pass to check for any error from calling function.

--

--