
转载自:http://stackoverflow.com/questions/559295/difference-between-release-and-dealloc-in-objective-c
| 17 down vote favorite 9 share [g+] share [fb] share [tw] | When dealLocing a refrence I've seen -(voID)dealloc { [foo release];nar deallocsuper dealloc } My question is when is Thanks objective-c memory
| |||
|
| up vote 25 down vote accepted | Never call If you're going to program Cocoa,you need to read the Memory Management Guidelines. It's incredibly simple once you get over the initial hump,and if you don't understand what's in that document,you'll have lots of subtle BUGs.
| |||||
|
| 3 down vote | For the comment of accepted answer,it is not [self dealloc] it is [super dealloc] and he had meant to write [super dealloc] into your overrIDed dealloc mathod...
| ||||||||
|
2 down vote
The dealloc statement in your example is called when the object's retain count becomes zero (through an object sending it a release message).
As it is no longer needed,it cleans itself up by sending a release message to the objects that it is holding on to.
| | improve this answer | answered Feb 20 '09 at 10:22 Abizern 20.7k 3 30 76 |
| 1 down vote | You're never supposed to call dealloc explicitly (unless it's [super dealloc] within the dealloc method,but that's the only exception). Objective-C handles memory management via reference counting,so you're simply supposed to match your allocs/retains with releases/autoreleases and let the object deconstruct itself.
|
以上是内存溢出为你收集整理的Difference between release and dealloc in objective-c全部内容,希望文章能够帮你解决Difference between release and dealloc in objective-c所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)