Set to nil in viewDidUnload, but release in dealloc
来源:互联网 发布:海岛奇兵火箭炮手数据 编辑:程序博客网 时间:2024/06/05 05:55
code sample should look like the following:
- (void)viewDidUnload { self .label = nil; [super viewDidUnload];}- (void)dealloc { [label release]; [super dealloc];}
When a low-memory condition occurs and the current viewcontroller’s views are not needed, the system may opt to removethose views from memory. This method is called after the viewcontroller’s view has been released and is your chance to performany final cleanup. If your view controller stores references to theview or its subviews, you should use this method to release thosereferences (if you retained the objects initially) and set thosereferences to nil. You can also use this method to release anyobjects that you created to support the view but that are no longerneeded now that the view is gone. You should not use this method torelease user data or any other information that cannot be easilyrecreated.
Typically, a view controller stores references to objects using anoutlet, which is a variable or property that includesthe IBOutlet
viewDidLoad
nil
.However, if you do not have an accessor method for a given object,you may have to release the object explicitly.
dealloc:在对象被销毁后被调用。
-release
idfoo = nil; [foo doSomething];
-doSomething
-viewDidUnload
,but don't nil it out, you'll crash when you try to release it againin-dealloc
,or if you use self.foo= somethingElse
self.label
-init
, -dealloc
,and a custom getter/setter. In those situations,use label
.The self->label
-copyWithZone:
- Set to nil in viewDidUnload, but release in dealloc
- 属性在viewDidUnload中设nil,在dealloc中却release
- Difference between release and dealloc in objective-c
- 【转】self.myOutlet=nil、viewDidUnload、dealloc的本质剖析
- CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
- Error using fmincon (line 816), Hessian option set to 'on' but no Hessian function provided in optio
- init viewdidload viewdidunload dealloc
- viewDidUnload和dealloc解释
- viewDidUnload、didReceiveMemoryWarning、dealloc
- init、viewDidLoad、viewDidUnload、dealloc
- viewDidUnload 和 dealloc
- dealloc & release
- null nil Nil [NSNull null] in Swift
- How to set the style in valuelist
- set environment in local to test
- set a breakpoint in malloc_error_break to debug
- set a breakpoint in malloc_error_break to debug
- How to use SET in python
- vim常用命令之多行注释和多行删除
- NSArray and KVC (muti-value per key)
- Erlang 函数(Efficiency Guide)
- NSString copy or retain
- KVO
- Set to nil in viewDidUnload, but release in dealloc
- OC遍历属性
- Android代码优化——使用Android lint工具
- Dynamic coding in Objective C
- 关于编写高质量的Python代码有感
- Creating custom UITableViewCell's within a Storyboard
- Beginning Storyboards in iOS 5 P…
- UISegmentedControl custom color
- 傅里叶变换有什么用?