iPhone释放dealloc

发布于 2024-09-11 23:00:23 字数 290 浏览 0 评论 0原文

我希望最好地理解 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

尘世孤行 2024-09-18 23:00:23

当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

黑凤梨 2024-09-18 23:00:23

只要这是 test 生命的终结,你就是对的。 test 的 Dealloc 将根据您的 [test release] 语句自动发生。

As long as that's the end of test's life, you're correct. Dealloc of test will automatically happen as a function of your [ test release] statement.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文