`
marlgl
  • 浏览: 73449 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Thu Rules of Cocoa Memory Management

阅读更多
   When you create an object using new, alloc, or copy, the object has a retain count of 1. You are responsible for sending the object a release or autorelease message when
you're done with it. That way, it gets cleaned up when its useful life is over.

   When you get hold of an object via any other mechanism, assume it has a retain count of 1 and that it has already been autoreleased. You don't need to do any further
work to make sure it gets cleaned up. If you're going to hang on to the object for any
length of time, retain it and make sure to release it when you're done.

   If you retain an object, you need to (eventually) release or autorelease it. Balance
these retains and releases.


That's it -- just three rules.

From: <<Learn Objective-C on the mac>>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics