Skip navigation.
 
mlRe: NSMutableArrya problems
FROM : mmalcolm crawford
DATE : Sat Dec 11 11:15:51 2004

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

Related mailsAuthorDate
mlNSMutableArrya problems Apirak Dec 11, 05:14
mlRe: NSMutableArrya problems Apirak Dec 11, 06:40
mlRe: NSMutableArrya problems Larry Fransson Dec 11, 08:08
mlRe: NSMutableArrya problems mmalcolm crawford Dec 11, 11:15
mlRe: NSMutableArrya problems mmalcolm crawford Dec 11, 11:23