A general question: When you add an item to an UIView, does that increase the owner count by 1? Does the main view that you added the item to now becomes an owner as well?
Example:
mainView = [[UIView alloc] init];
UILabel *label = [[UILabel alloc] init];
[mainView addSubview:label] //does this increase owner count by 1?
[label release] //and this decreases it by 1?
You release what you retain/init.
When you call
addSubview:, it increases the retain count (or as you say owner count). But that increase belongs tomainView. So it is up tomainViewto release the subview some point in the future, not you.So when you
initthe label it increases the retain count to 1. When you calladdSubview:labelit increases the retain count by 1, to 2. Then you release the label, decreasing the retain count back to 1 and counteracting you’re previous init.Then when the label is removed from the mainView its retain count will go back down to 0 and it will be deallocated.
Never use the method
retainCount, whether you’re just observing it, or acting on it. This method will not display what you expect because of a lot of behind the scenes code. Just don’t useretainCount.