sending release to nil
sending release to nil
- Subject: sending release to nil
- From: Ted Lowery <email@hidden>
- Date: Wed, 15 Jan 2003 23:29:52 -0500
Hi all-
As an ex-C++ programmer (I say 'ex' because I am completely sold on the
ease of development and features of objective-C, now if I can only find
a paying job...), I am used to the limitation of not being able to free
an object more than once. Early on, my code was littered with:
if (obj) delete obj;
obj = NULL;
Then, as I learned, I created a free pattern (idea courtesy of Mike and
Phani):
#define kill(x) if (x) delete x; x = NULL;
then I could free an object as much as I wanted.
Anyhow, now that I am discovering the power of objective-C, I notice I
can send nil a release message, and it really doesn't care. So my
current pattern is:
if (obj) [obj release];
obj = nil;
but I can also drop the if part, and code works fine.
My question is (I know, you were wondering if I would ever get to it?):
There is a performance hit for using if, and I assume there is a
performance hit for sending release to nil. I would surmise the if is
faster than messaging all the way to nil, though obj-C may do something
cool for me that mitigates. Of course, I could be dead wrong as well.
I'm too lazy to build a test case, so I thought I'd pose to this group.
Hang on, the question is coming, I promise...
What patterns do you use?
if?
multiple releases to nil?
does it make a measurable difference if I bracket the release and nil
assignments?
something else I'm not thinking of?
Thanks for the help, everyone.
Cheers, Ted
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.