How many times do I release an allocated or retained object?

后端 未结 2 1062
谎友^
谎友^ 2020-11-28 14:46

I am making an iPhone game. I want to release all objects that have been allocated or retained. In the dealloc function I am releasing all such objects, but the

相关标签:
2条回答
  • 2020-11-28 15:12

    Do not use -retainCount.

    The absolute retain count of an object is meaningless.

    You should call release exactly same number of times that you caused the object to be retained. No less (unless you like leaks) and, certainly, no more (unless you like crashes).

    See the Memory Management Guidelines for full details.

    0 讨论(0)
  • 2020-11-28 15:23

    Autorelease makes retainCount meaningless. Keep track of retains & whether you own an object. Study & remember these rules: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html#//apple_ref/doc/uid/20000994-BAJHFBGH

    0 讨论(0)
提交回复
热议问题