In my view, I have multiple views (UICollectionViewCell
s) that, depending on the model, can include an UIImageView
as a subview (each with a separate instance).
For my case, the views that don't show the UIImageView
outnumber the ones that do show it.
I can choose to either call UIImageView.hidden = false
when I want the views to show the image, or to set the image inside the image view i.e. UIImageView.image = UIImage(named: ...)
.
I'm wondering, which is the more performant approach, with memory and speed concerns? I have a feeling that the difference is not significant enough, especially with UIImage(named:)
's caching, but I do want to find out.
if you set UIImageView.image = nil
, then surely if an image is in memory, it will be released (then reallocated if reused), so I suggest always to do it
if you want to be sure that UIImageView.image
(1) will not be visible, (2) does not occupy a frame
in the cell
and (3) will not imply rendering time, then also set UIImageView.hidden = true
I suggest to take both actions. Performances are not a problem here, in my opinion (considering also that you have very few cells with image inside)
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