开发者

Do I have to call release on an objective-c retain class variable when setting it to a new object?

Say I have:

@pro开发者_JS百科perty (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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜