Cocoa内存管理

Cocoa关于对象及保留计数器的3条规则:

1、如果使用newalloccopy操作获得一个对象,则该对象的保留计数器值为1。

2、如果通过其他任何方法获得一个对象,则假设该对象的保留计数器值为1,而且已经被设置为自动释放。

3、如果保留了某个对象,则必须保持retain方法和release方法的使用次数相等。

其实归结起来就一句话:如果使用了newalloccopy获得一个对象,则必须释放或自动释放该对象。

 

Cocoa has three rules about objects and their retain counts:
■ If you get the object from a new, alloc, or copy operation, the object has a retain count of 1.
■ If you get the object any other way, assume it has a retain count of 1 and that it has been autoreleased.
■ If you retain an object, you must balance every retain with a release.

You’ll be safe if you remember the mantra, “If I get it from new, alloc, or copy, I have to release or autorelease it.”

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值