Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible that a weak reference might be garbage collected while I am using its parent in IOS?

Tags:

ios

Say I have a parent UIView. This UIView has a weak pointer to a subview UIImageView. If UIView is currently displayed on the screen, is it possible for the image view to be garbage collected since the parent UIview only has a weak reference to the UIImageView?

FYI UIview and UIImageView would both be on the screen

like image 811
user1099123 Avatar asked Nov 18 '25 10:11

user1099123


1 Answers

This UIView has a weak pointer to a subview UIImageView

Stop. If the UIImageView is a subview of the UIView, then the UIView has a strong pointer to the UIImageView. End of story.

In other words, a view retains its subviews. As long as the subview is a subview, it cannot vanish in a puff of smoke.

Now, on the other hand, if you remove that subview, then you have to worry about its memory management or it might vanish in a puff of smoke.

like image 92
matt Avatar answered Nov 20 '25 03:11

matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!