iOS - 我收到内存警告但不知道为什么
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9046595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS - i receive memory warnings but have no idea why
提问by Erik Sapir
I am developing for the iOS and checking my app with IPhone and IPad.
我正在为 iOS 开发并使用 iPhone 和 iPad 检查我的应用程序。
I receive many memory warnings (didReceiveMemoryWarning is called) but have no idea why. My app is using ~35MB in the peak points, and 4-5 MB when it the lowest point.
我收到很多内存警告(didReceiveMemoryWarning 被调用)但不知道为什么。我的应用程序在峰值点使用~35MB,在最低点使用4-5MB。
I tried to find leaks using 'instruments' but could not find any critical issues.
我尝试使用“仪器”查找泄漏,但找不到任何关键问题。
Is there a good way to find out why the system sends memory warnings?
有没有什么好办法可以找出系统为什么会发送内存警告?
回答by X Slash
Memory warning is to be expected in an iOS app. It doesn't have to be because of your app. Other apps are still in memory even if the apps are suspended. The OS will do memory management by sending memory warning and kill apps when necessary. As long as you're using reasonable amount of memory (with little to no memory leak) and handle didReceiveMemoryWarning properly, you'll be fine.
在 iOS 应用程序中会出现内存警告。这不一定是因为您的应用程序。即使应用程序被暂停,其他应用程序仍在内存中。操作系统将通过发送内存警告并在必要时终止应用程序来进行内存管理。只要您使用合理数量的内存(几乎没有内存泄漏)并正确处理 didReceiveMemoryWarning,您就可以了。
Also, when your app is in suspended mode, if your app is using little memory footprint, your app will more likely to survive killing process. As app with larger memory footprint will be terminated first.
此外,当您的应用程序处于挂起模式时,如果您的应用程序占用的内存很少,那么您的应用程序将更有可能在终止过程中幸存下来。由于内存占用较大的应用程序将首先终止。
回答by DJ van Wyk
I also found that "Product -> Analyze" (Shift+Command+B) can help you sort out some code issues before you start using Leaks. With the introduction of ARC this became less useful though.
我还发现“产品 -> 分析”(Shift+Command+B)可以帮助你在开始使用 Leaks 之前解决一些代码问题。但是,随着 ARC 的引入,这变得不那么有用了。