It’s not clear, to me anyway, if a UIView is automatically released from its superview if you use addSubview to add it to another view?!? I know a view can only have ONE superview but I’m not clear about how, exactly, to go about moving a subview from one superview to another.
retain view, release (from old superview), addSubview to new superview
or
simply addSubview to new superview?
To the question of whether the view is released when
-removeFromSuperViewis called, it is, and this is documented in the UIView reference under-removeFromSuperView. It is not as explicitly stated that-addSubView:calls-removeFromSuperView, but it is implied and can be tested by overloading-removeFromSuperViewin a UIView subclass.Therefore I can think of no reason to call
-removeFromSuperViewin this case. There’s no memory-management reason to do it, so this is adding some code complexity (and therefore potential errors) for little value. Even in cases where I wanted to emphasize to later developers that this view is changing view hierarchy, I would use a comment rather than the extra retain/release here.