开发者

object relesed, how about its property's?

开发者 https://www.devze.com 2023-02-13 01:58 出处:网络
my 开发者_C百科question is : i think that there is an error in this code ( it is not my code and i have not a Mac to compile ). this is the code :

my 开发者_C百科question is : i think that there is an error in this code ( it is not my code and i have not a Mac to compile ). this is the code :

....

CDAUIView *theView = [[CDAUIView alloc] initWithFrame:rectFrame];

theView.myController = self;
self.view = theView;
[theView autorelease];

when theView is released, wha about its property ( myController) ??

thanks for your answers


It all depends on the details behind the properties in question (specifically, whether the properties are declared as retain, copy or assign) — but that code looks fine, given reasonable assumptions. Under normal circumstances, setting a property will retain the object, and releasing the object might cause its properties to be released (that will happen if the object is deallocated). In this case, releasing the view shouldn't cause its myController to be released, because it's still being owned by self here. But even if it were, the release would just be balancing the retain.

An object doesn't retain its instance variables whenever it's retained, and it doesn't release them just because it's released. It retains them when it takes ownership it and releases them when it is ready to relinquish ownership.


If CDAUIView is written correctly, when it gets deallocated it will release any objects that it has retained.

0

精彩评论

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

关注公众号