Re: [OT] Retain count riddle
Re: [OT] Retain count riddle
- Subject: Re: [OT] Retain count riddle
- From: Chris Hanson <email@hidden>
- Date: Thu, 1 Apr 2004 12:16:30 -0600
On Mar 31, 2004, at 4:34 PM, Jonathan E. Jackel wrote:
Assume the worst. You do not need to know whether [path
lastPathComponent]
returns a new object or a weak ref to the same object. Either way,
retaining it while you need it and releasing it when you are done will
work.
So just do that.
What's more, you need to be aware when you should copy rather than
retain. In particular, if you're writing a setter, and you're getting
an object that might be mutable that you don't want being changed
behind your back, you should copy it.
That's why in my example I wrote -setPath: to copy rather than retain.
It could easily be passed an NSMutableString that someone else could
change; most of the time you want a string to be an attribute rather
than a relationship, so I copied it.
-- Chris
--
Chris Hanson <email@hidden>
http://www.livejournal.com/users/chanson/
_______________________________________________
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.