The anatomy of CFRelease(CFType type) and NSObject protocol’s -release message.
CFRelease(), defined in CFBase releases a CFType instance.
– release sends a release message to any of the NSObject derived class instance.
In theory, both of these does the same job but applied to different types.
We can define macros as shown,
#define _RELEASE(_obj) [_obj release]; _obj = nil;
#define _CFRELEASE(_obj) if(_obj) CFRelease(_obj);
The only difference, as we can observe, is that it is important to check the pointer for a non-null value before calling CFRelease, otherwise runtime crash occurs. However, we do not need to check the NSObject’s instance of non-null value since sending release message to a nil NSObject instance is perfectly valid and does not cause any crash.
The next statement sets NSObject’s instance to nil. This prevents from a crash as result of accidently made message calls to _obj instance after releasing it. Again, sending any message to nil is perfectly valid in Objective-C.