Do we really need a safe release macro?

Posted by Ian1971 on Stack Overflow See other posts from Stack Overflow or by Ian1971
Published on 2011-02-21T16:37:13Z Indexed on 2011/03/02 7:24 UTC
Read the original article Hit count: 229

Filed under:

Quite a lot of people seem to use a macro such as

#define SAFE_RELEASE(X)  [X release]; X = nil;

(myself included).

I've been reassessing why I am using it and wanted to canvas some opinion.

The purpose (I think) for using this macro is so that if you were to accidentally use your object after releasing it then you won't get a bad access exception because objective-c will quite happily ignore it when the object is nil.

It strikes me that this has the potential to mask some obscure bugs. Maybe it would actually be preferable for the program to crash when you try to use X again. That way during testing you can find the issue and improve the code.

Does this macro encourage lazy programming?

Thoughts?

© Stack Overflow or respective owner

Related posts about objective-c