iPhone释放dealloc
我希望最好地理解 dealloc 和 release 函数之间的区别...... 例子... 我的类派生自 NSObject calle MyClass 在我的代码中,要使用此类,我创建了 MyClass 的实例..
// initialization
MyClass* test = [[MyClass alloc] init];
//do some stuff....
// release??
[ test release];
是吗?和dealloc???需要按顺序使用或一个覆盖另一个?
I wish best understand the difference between dealloc and release function....
example...
I have my class derived from NSObject calle MyClass
in my code, to use this class, I create an instance of MyClass..
// initialization
MyClass* test = [[MyClass alloc] init];
//do some stuff....
// release??
[ test release];
is right?? and the dealloc??? needs to be used in sequency or one overwrite the other??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当retainCount == 0 时,会自动调用dealloc。每次调用[test release],retainCount 都会减1。
在您的示例中,一切都很好,因为您进行了分配测试(保留计数+1),然后释放(保留计数0)。 Dealloc会被自动调用
dealloc is automatically called when retainCount is == 0. Each time you call [test release] the retainCount is decreased by one.
In your example everything is fine, since you have alloc test (retain count +1) and then release (retain count 0). Dealloc will be automatically called
只要这是
test
生命的终结,你就是对的。test
的 Dealloc 将根据您的[test release]
语句自动发生。As long as that's the end of
test
's life, you're correct. Dealloc oftest
will automatically happen as a function of your[ test release]
statement.