简体   繁体   English

如何正确“清理”在Swift中从Superview中删除的UIView? -iOS

[英]How to properly “clean” a UIView that was removed from Superview in Swift? - IOS

I guess i might not understand how memory deallocates in Swift properly and thats why i wanted to ask this: If i create a Message to the user using a UIView with a Label. 我想我可能不明白如何在Swift中正确分配内存,这就是为什么我要问这个问题:如果我使用带有标签的UIView向用户创建消息。 i show it with an animation and then use ".removeFromSuperview()". 我用动画显示它,然后使用“ .removeFromSuperview()”。 when does it's memory deallocates? 什么时候内存会释放? what are the conditions for it to deallocate? 它要解除分配的条件是什么? Im asking because if it doesn't deallocate until the app closes - it means that for the run of the app - each message shown and then hidden will take up memory for no good reason. 我问,因为直到应用程序关闭它才会释放-这意味着对于应用程序的运行-显示并隐藏的每条消息都没有充分的理由占用内存。

Thanks for anyone who explains :) 感谢任何解释的人:)

Views maintain a strong reference to their subviews. 视图对其子视图保持强烈引用。 Once the subview is removed, the superview relinquishes this reference. 删除子视图后,超级视图将放弃该引用。 If you have no other strong references the retain count will decrement to zero and the view will be released. 如果没有其他强引用,则保留计数将减少为零,并且视图将被释放。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM