does addSubview increment retain count?

半腔热情 提交于 2019-11-29 07:17:02

Yes, "addSubview" increases the retain count. This makes sense because the method stores the subview which should not be released/freed until the superview is also released. When the superview is release it also releases all its subviews.

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.

If you +new/+alloc/-retain/-copy (NARC) an object, you need to balance the retain with a release (or autoerelease). End of story. The absolute retain count, especially the absolute retain count of an instance of a class that is subclassed from a framework class and/or passed into framework code, is an implementation detail and quite likely to not be what you think it should be.

Actually it does. You can refer this at http://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html#//apple_ref/occ/instm/UIView/addSubview:

As a matter of course, the superView retains the subView on addSubview: , so it does release when removes the subView.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!