We take pride in your success. We let our positivity drive us, day in and out. Talk to us at Mindfire to know us more.

Software Technology Tips

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.


Related Tags:

Objective-C, CoreFoundation, CFRelease

Author: Mithlesh Jha

top

Miscellaneous

Let us Connect!

privacy

copyright (c) Mindfire Solutions 2007-2012. Login