I am using UIActivityIndicator within a table cell’s accessoryView. Actually it is a subview of anotherView (which is the cell’s accessoryView) as seen below:
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
[anotherView addSubview:activityIndicator];
[activityIndicator startAnimating];
[activityIndicator release];
cell.accessoryView = anotherView;
For my use case, I do not need to access the indicator view any more. Also if the complete view will be removed (due to dismissing the ViewController), I am not caring about those UIActivityIndicators.
So will this type of usage be safe and not create any memory/resource leftovers? I have checked, that dealloc of UIActivityIndicatorView is called (and it is), so I would assume the animation will be stopped/removed automatically as well while the view hierachy is destroyed.
Is my assumption correct?
Yes, once you’ve relinquished ownership of the indicator, the view hierarchy remains the only owner. If a superview is removed from the view hierarchy and if it is not retained elsewhere, the superview releases all its subviews. If the subviews hit a retain count of zero, they are deallocated. This is what is happening with your indicator view.