问题描述
我有一个 UITableView
作为我的第一个屏幕与 UINavigation
控制器。
I have a UITableView
as my first screen with a UINavigation
controller.
在我的第一个屏幕我 NSLog(@主屏幕保留计数=%d,[self retainCount]);
这是否正确?
推荐答案
retainCount是对象上所有权声明的数量。
The retainCount is the number of ownership claims there are outstanding on the object.
使用名称以alloc或new开头或包含copy(例如alloc,newObject或mutableCopy)的方法或者如果向其发送保留消息来创建它。所有这些都增加了retainCount。
You take ownership of an object if you create it using a method whose name begins with "alloc" or "new" or contains "copy" (for example, alloc, newObject, or mutableCopy), or if you send it a retain message. All of these increment the retainCount.
使用release或autorelease放弃所有权。这些减少了retainCount。
You relinquish ownership with using "release" or "autorelease". These decrement the retainCount.
但是你不应该注意retainCount的值,这是最令人困惑的,在最坏的误导。只需按照操作,即可获取所有权你需要保存一个对象的引用,并在完成后放弃所有权,并且你不会有问题。
However you should never pay any attention to the value of retainCount, it is at best confusing, at worst misleading. Simply follow the memory management rules - take ownership when you need to keep a reference to an object and relinquish ownership when you are finished, and you wont have a problem.
如果你正在查看retainCount,事情的方式错误,你只会进一步混淆自己。
If you are looking at retainCount, you are going about things the wrong way, and you will simply confuse yourself further.
这篇关于什么是ObjectiveC的retainCount?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!