Objective-C中Release和Dealloc之间的区别 [英] Difference between release and dealloc in objective-c

查看:114
本文介绍了Objective-C中Release和Dealloc之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

取消分配引用时,我已经看到例如使用releasedealloc

When deallocing a refrence I've seen release and dealloc being used for example

-(void)dealloc
{
  [foo release];
  [nar dealloc];

  [super dealloc];
}

我的问题是何时使用release,何时使用dealloc?

My question is when is release to be used and when is dealloc to be used?

谢谢

推荐答案

在类的dealloc方法末尾,除非以[super dealloc]的形式调用,否则请勿调用dealloc. release方法放弃对象的所有权.当可可对象不再拥有任何所有者时,可以将其释放-在这种情况下,将自动向其发送dealloc消息.

Never call dealloc except as [super dealloc] at the end of your class's dealloc method. The release method relinquishes ownership of an object. When a Cocoa object no longer has any owners, it may be deallocated — in which case it will automatically be sent a dealloc message.

如果要编写Cocoa程序,则需要阅读

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.

这篇关于Objective-C中Release和Dealloc之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆