What is best for the device when temporarily hiding a view (e.g. until loading is done)?
Which is best in terms of memory and which is best in terms of performance? I know Apple somewhere wrote something about this, but I can't find it.
Which is best in terms of memory
removeFromSuperview
is the best in term of memory. Why ? Because it will cause the view to be released. So if the view is not retained by anyone else (like a strong ivar), it will be deallocated.
And which is best in terms of performance?
setHidden:
is the best in terms of performance. Why ? Because the action is just to set a flag. And then in drawRect it's just a BOOL check. So it's really fast because there is no other action involved.
So, the fastest method first:
setHidden
(discard view from rendering only)alpha
to 0
is Equal to setHidden, but it first checks if
0`removeFromSuperView
(need some steps: deallocate object, pop from stack (pointer), remove from rendering stack...)frame.origin.y=-10000
> must move a whole bit array and check if the view comes out of bounds. not very fast...If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With