UIView内存释放
我什么时候必须在下面的代码中释放 UIView
?
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(20, 10,
120.0, 100)];
return headerView;
感谢您的帮助
When do I have to release UIView
in the below code?
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(20, 10,
120.0, 100)];
return headerView;
Thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这取决于您将如何使用该视图。如果将从方法返回的视图分配给某个对象(例如 UIViewController)并且该对象保留它,那么您应该在上述函数中自动释放该视图。这样,您将确保它在方法循环结束后自动释放,并且它的活动时间足以让对象保留它。所以代码将是这样的:
例如:
It depends on how you're going to use the view. If you assign the view returned from the method to some object (for example to a UIViewController) and that object retains it then you should autorelese the view in the above function. This way you'll make sure that it gets released automatically after the method loop ends and also it'll be alive long enough for an object to retain it. So the code will be like this:
For ex:
将其作为自动释放返回。使用此功能的人将负责其所有权。 查看此内容发布。
return it as auto-release. The one who uses this functions will take care of its ownership. See this post.