收到内存警告。 Level=1 - 具有 5 个选项卡的 UITabBarController 应用程序
我的应用程序由 5 个选项卡组成。其中 4 个包含大约 20 个文本字段(以编程方式创建并作为子视图添加到视图中), 我的最后一个选项卡是之前选项卡的预览(屏幕截图)。当用户转到此选项卡时,他应该能够预览,并可以选择触发带有预览的电子邮件(将所有 4 个选项卡的屏幕截图附加到电子邮件中)我已成功实现此操作,但导致出现内存警告。任何帮助解决我的问题将不胜感激。
我以这种方式尝试过:如果视图不可见,则在 didReceiveMemoryWarning 中释放对象
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
if (!self.view.window) {
[preparedForTextField release];
[agentTextField release];
[phoneTextField release];
[dateTextField release];
[textFieldsArray release];
}
// Release any cached data, images, etc. that aren't in use.
}
,并在 viewDidLoad 中再次重新加载视图。我仍然收到内存警告。
My Application consists of 5 tabs. Where 4 of them contains at around 20 textfields (created pro grammatically and added as subview to the view) in each,
my last tab is a preview for the previous tabs (screenshots). When user goes to this tab he should be able to preview and has an option to trigger an email with the preview, (attaching all 4 tabs screenshots to the email) I have implemented this successfully but resulted with memory warnings. Any help would be appreciated to resolve my issue.
I tried it in this way: Released objects in didReceiveMemoryWarning if the view is not visible
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
if (!self.view.window) {
[preparedForTextField release];
[agentTextField release];
[phoneTextField release];
[dateTextField release];
[textFieldsArray release];
}
// Release any cached data, images, etc. that aren't in use.
}
and reloaded the view again in viewDidLoad. Still I am getting memory warnings.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您需要内存中的所有内容都在那里,请忽略内存警告(尤其是 1 级警告很容易出现)。如果您不需要其中的所有内容并且可以稍后重新加载或重新创建现在不需要的内容,请将其从内存中删除直到需要为止(然后重新加载或重新创建它)。
If you need all the stuff that you have in memory to be there, just ignore the memory warning (especially the level 1 warning comes quite easily). If you don't need all of it there and can later reload or recreate what you don't need now, remove it from memory until needed (and then reload or recreate it).