retaincount

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

喜你入骨 提交于 2019-11-26 08:30:37
问题 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 then I realized that sometimes I end up releasing objects when they have not been allocated yet. So I figured I need to check if its retainCount is greater than zero or not before I release it. My question is: Do I just check if the retainCount is greater than zero and then release it? if([bg retainCount]!=0) { [bg release]; } or Should I

Calling -retainCount Considered Harmful

只愿长相守 提交于 2019-11-26 01:54:38
Or, Why I Didn't Use retainCount On My Summer Vacation This post is intended to solicit detailed write-ups about the whys and wherefores of that infamous method, retainCount , in order to consolidate the relevant information floating around SO.* The basics: What are the official reasons to not use retainCount ? Is there ever any situation at all when it might be useful? What should be done instead?** Feel free to editorialize. Historical/explanatory: Why does Apple provide this method in the NSObject protocol if it's not intended to be used? Does Apple's code rely on retainCount for some

Calling -retainCount Considered Harmful

蹲街弑〆低调 提交于 2019-11-26 01:08:41
问题 Or, Why I Didn\'t Use retainCount On My Summer Vacation This post is intended to solicit detailed write-ups about the whys and wherefores of that infamous method, retainCount , in order to consolidate the relevant information floating around SO.* The basics: What are the official reasons to not use retainCount ? Is there ever any situation at all when it might be useful? What should be done instead?** Feel free to editorialize. Historical/explanatory: Why does Apple provide this method in the

When to use -retainCount?

穿精又带淫゛_ 提交于 2019-11-25 22:16:45
问题 I would like to know in what situation did you use -retainCount so far, and eventually the problems that can happen using it. Thanks. 回答1: You should never use -retainCount , because it never tells you anything useful. The implementation of the Foundation and AppKit/UIKit frameworks is opaque; you don't know what's being retained, why it's being retained, who's retaining it, when it was retained, and so on. For example: You'd think that [NSNumber numberWithInt:1] would have a retainCount of 1