开发者

How to get the reference count of an NSObject?

开发者 https://www.devze.com 2022-12-27 02:32 出处:网络
Is there a way to fetch the curren开发者_运维技巧t reference count for an NSObject (i.e. NSString)?retainCount

Is there a way to fetch the curren开发者_运维技巧t reference count for an NSObject (i.e. NSString)?


retainCount

But you should consider using CFGetRetainCount instead


As @Ben S said, it's the retainCount method. However, you're asking the wrong question, because:

Important: Typically there should be no reason to explicitly ask an object what its retain count is (see retainCount). The result is often misleading, as you may be unaware of what framework objects have retained an object in which you are interested. In debugging memory management issues, you should be concerned only with ensuring that your code adheres to the ownership rules.

So here's the real question: why do you need to know?


using CFGetRetainCount function

Example :

print(CFGetRetainCount(object))

Read more here.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号