OC_内存管理的原则

 

1. You own any object you create by allocating memory for it or copying it.Related methods:alloc,allocWithZone: mutableCopy,mutableCopyWithZone:

译: 你拥有任意一个你创建的对象为他分配内存或复制它。相关的方法:alloc,allocWithZone:mutableCopy mutableCopyWithZone:


2. If you are not the creator of an object, but want toensure it stays in memory for you to use, you can express anownership interest in it.Related method:retain

译: 如果你不是一个对象的创造者,但要确保它保持在内存中供您使用,你可以声明对它的所有权(使它的引用计数+1)。相关的方法:retain


3. If youown an object, either by creating it or expressing an ownership interest, you are responsible forreleasing it when you no longer need it. Related methods:release,autorelease

译:如果你拥有一个对象,无论通过创建还是声明(通过上面⬆️)获得的所有权,当你不再需要它,你负责释放它。相关的方法:release,autorelease


4. Conversely, if you are not the creator of an object and have not expressed an ownership interest, you must not release it.

译: 相反,如果你没有对象的创建者和没有声明对它的所有权,你不能释放它。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值