Difference between UIImageView.hidden and UIImageView.image = nil

In my opinion, I have several views ( UICollectionViewCell s) which, depending on the model, may include UIImageView as a subheading (each with a separate instance).

In my case, views that don't show UIImageView outperform numbers that show this.

I can choose to either call UIImageView.hidden = false when I want the views to display the image, or to set the image inside the image, i.e. UIImageView.image = UIImage(named: ...) .

I wonder which one is more efficient, with memory and speed issues? I have a feeling that the difference is not significant enough, especially when caching UIImage(named:) , but I want to find out.

+6
source share
2 answers
  • if you set UIImageView.image = nil , then if the image is in memory, it will be released (then redistributed if it will be reused), so I suggest that you always do this

  • if you want to be sure that UIImageView.image (1) will not be visible, (2) does not occupy the frame in the cell and (3) does not mean rendering time, then also set UIImageView.hidden = true

I suggest taking both actions. The performances here are not a problem, in my opinion (given that you have very few cells with the image inside)

+2
source

nil - this action means that what was selected by imageview will be freed from memory.

hidden - the imageview still points to this memory location, but it is hidden in its parent view.

0
source

All Articles