管理 IOS 中的内存警告。有什么指点吗?
在我的应用程序中,有时我会收到 1 级内存警告,考虑到它正在执行的工作量,我认为这是可以接受的。当发生这种情况时,它会为属于 tabbarviewcontroller 的视图之一调用 viewdidunload 。在 viewdidunload 中,我将插座设置为零,我认为这是完全正常的。
如果我尝试再次访问该类,就会出现问题。由于它已被释放,它将引发错误的访问错误,从而阻止我再次显示该视图。如果我不将这些出口设置为 nil,那么它不会崩溃,这是正常的,但惯例总是在 viewdidunload 中将任何出口设置为 nul。
在这种情况下有处理内存警告的指针吗?我不想删除 viewdidunload 方法中的代码,因为它违反了惯例。
我忘了补充一点,我对 tabbarcontroller >_< 进行了子类化
in my app, sometimes I get a level 1 memory warning which I think is acceptable given the amount of work it is doing. When that happens, it calls the viewdidunload for one of the views which is part of the tabbarviewcontroller. In the viewdidunload, i set the outlets to nil which I think is totally normal.
The issue arises if I try to access that class again. Since it was deallocated, it will throw a bad access error which prevents me from showing that view again. If I don't set those outlets to nil then it won't crash which is normal but the convention is always to set any outlets to nul in the viewdidunload.
Any pointers for handling memory warnings in this case? I don't want to delete the code i have in the viewdidunload method since it is going against the convention.
I forgot to add that i subclassed the tabbarcontroller >_<
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在这种情况下,当您再次加载该视图时,将再次分配添加到 xib 文件的子视图。如果您想自定义某些内容,请在 viewDidLoad 方法中执行此操作。
In that case, again the subviews added to xib file will be allocated when you load that view again. And if you want to customize something, do that in
viewDidLoad
method.被解除分配的视图在哪里分配?听起来您正在取消分配
viewDidUnload
中未分配的视图,例如viewDidLoad
中。相反,它可能是在其他地方创建的,因此在重新加载 viewController 的视图后不会重新创建它。Where do the views which were deallocate get allocated? It sounds like you are deallocating a view in
viewDidUnload
that was not allocate in, for example,viewDidLoad
. Instead it might have been created somewhere else, so it does not get recreated then the viewController's view is reloaded.