Re: [OT] Retain count riddle
Re: [OT] Retain count riddle
- Subject: Re: [OT] Retain count riddle
- From: Shawn Erickson <email@hidden>
- Date: Tue, 30 Mar 2004 12:17:08 -0800
On Mar 30, 2004, at 11:49 AM, Sailesh Agrawal wrote:
So I had this bug the other day that I thought would make an
interesting
riddle.
The code looked like this:
#define SAFE_SET(old, new) [new retain]; [old release]; old = new;
...
- (void) foo : (NSString*)path {
SAFE_SET(m_Path, [path lastPathComponent]);
}
Now the problem was any time I accessed m_Path my app would crash.
This
isn't cocoa specific, I'm just dumb for using macros where I should
have
been using a function. Can anyone guess what the problem is ?
The macro expands to this...
[[path lastPathComponent] retain];
[m_Path release];
m_Path = [path lastPathComponent];
Note two different calls to lastPathComponent with the last call's
returned object not being retained.
-Shawn
_______________________________________________
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.