Re: NSMutableArrya problems
Re: NSMutableArrya problems
- Subject: Re: NSMutableArrya problems
- From: mmalcolm crawford <email@hidden>
- Date: Sat, 11 Dec 2004 02:15:51 -0800
On Dec 10, 2004, at 11:08 PM, Larry Fransson wrote:
Another helpful tip:
- (void) setWord:(NSString *)newword {
word = newword;
}
That will leak memory every time you call it. It should be written
more like this:
Umm, no, it doesn't leak memory, it simply reassigns the pointer. What
is important is that it doesn't retain new word. Thus if and when
newword is deallocated the reference becomes invalid, typically with
unpleasant consequences...
- (void)setWord:(NSString *)newWord
{
[newWord retain];
[word release];
word = newWord;
}
For "property list" attributes, (to ensure proper encapsulation) you're
usually recommended to copy rather than retain the new value -- see for
example:
<http://www.stepwise.com/Articles/Technical/2002-06-11.01.html>
mmalc
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden