开发者

About memory management (spec for object create by Interface builder)

I have a question on free object memory in object c .

for example code :

@interface myCell : UITableViewCell {

    IBOutlet UIView* bindView;

    IBOutlet UIView* unBindView;

}

as you see, two object , first was assign and bind via Interface Builder , another is no

in my dealloc code , I try to free it to avoid memory leak . so I do as follow:

- (void)dealloc {


    [bindView release];
    bindView = nil;

    [unBindView rele开发者_运维知识库ase];
    unBindView = nil;

    [super dealloc];
}

so, I think that will be free all..... the code execute properly , but I am strange that because the second object unBindView never assign in code or by IB, that seem should be nil, but the code still can be executed no nil pointer exception throws ....

my question, is whether my free object code above is right and best way ? because the bindView never been retained , I think that should be handle by cocoa ? the next question is about unBindView, as I know object is weak language, but what the rule about this type variable usage ?

thanks for you answers !


because the second object unBindView never assign in code or by IB, that seem should be nil, but the code still can be executed no nil pointer exception throws ....

In Objective-C, sending messages to nil simply results in nothing happening. That's why you don't get exceptions. On one hand it's really convenient; on the other hand, it can be pretty hard to track down, and it's not expected in all cases.

my question, is whether my free object code above is right and best way ?

I think it's fine. The = nil lines aren't necessary since the view controller would already have been deallocated at the time that is called, but I don't think it should negatively affect your app's code.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜