views:

41

answers:

1

Say I have:

@property (nonatomic,retain) NSString *foo;

in some class.

And I call:

myclass.foo = [NSString stringWithString:@"string1"];
myclass.foo = [NSString stringWithString:@"string2"];

Should I have called [myclass.foo release] before setting it to "string2" to avoid a memory leak?

Or the fact that nothing is pointing to the first "string1" object anymore is good enough?

And in the dealloc method [foo release] will be called.

+3  A: 

From the Apple Docs on declared properties:

retain
Specifies that retain should be invoked on the object upon assignment. (The default is assign.)
The previous value is sent a release message.

Georg Fritzsche