Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [OT] Retain count riddle



why not just: #define SAFE_SET(old,new) [old release]; old = [new retain];
or am i just being stupid?


2004-03-30 kl. 23.00 skrev Steve Stockman:

On Mar 30, 2004, at 1:49 PM, 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;

Others have already pointed out the leak and the crash, but if you still want to use a macro, I would suggest redefining it as:

#define SAFE_SET(old,new) do { id _temp=[(new) retain]; [old release]; old=_temp; } while(0)

--
Steve Stockman
Architect, Norton Utilities for Macintosh
Symantec Corporation
_______________________________________________
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.
_______________________________________________
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.


References: 
 >[OT] Retain count riddle (From: "Sailesh Agrawal" <email@hidden>)
 >Re: [OT] Retain count riddle (From: Steve Stockman <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.