setNeedsDisplay 释放子视图?
如果自定义视图根据条件if
向自身添加多个子视图,并且稍后在条件不再truesetNeedsDisplay
code> 因此这些子视图没有被创建,“旧”子视图是否在drawRect
期间自动从内存中释放?
或者,我是否应该担心检查子视图是否存在,释放它们,然后setNeedsDisplay?
我想最终我的问题是关于 setNeedsDisplay 的内存影响,如果它有效地从内存中删除旧视图及其子视图,然后从头开始重新创建视图?
If a custom view adds several subviews to itself based on a condition if
, and later a setNeedsDisplay
is called on this view where the condition is no longer true
and thus these subviews are not created, are the "old" subviews automatically released from memory during the drawRect
?
Or, should I worry about checking for the presence of subviews, releasing them, then setNeedsDisplay
?
I guess ultimately my question is about the memory implications of setNeedsDisplay
, if it effectively removes from memory the old view and its subviews and then essentially recreates the view from scratch?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
-setNeedsDisplay 只是设置一个标志,表示“此视图需要重绘”。据我所知,它不会保留或释放任何内容,也不会添加或删除任何子视图。
我不确定你想做什么,但听起来你担心太多了。当应用程序的状态发生变化,需要重新绘制给定视图时,请调用 -setNeedsDisplay。如果您随后从视图层次结构中删除该视图,则不会导致任何问题。
-setNeedsDisplay just sets a flag that says "this view needs to be redrawn." As far as I know, it doesn't retain or release anything, or add or remove any subviews.
I'm not sure what you're trying to do, but it sounds like you're worrying too much. Call -setNeedsDisplay when your app's state has changed in a way that requires a given view to be redrawn. If you subsequently remove that view from your view hierarchy, that shouldn't cause any problem.