xcode 收到内存警告和应用程序崩溃
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15405519/
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
Received memory warning and app crashes
提问by Purva
my app is crashing due to Received memory warning.
由于收到内存警告,我的应用程序崩溃。
If i run the app for few minutes then on doing anything, the app crashes straightaway.
如果我运行应用程序几分钟然后在做任何事情,应用程序会立即崩溃。
I have even checked for memory leaks but there are no memory leaks. Also the app is working fine in simulator.
我什至检查了内存泄漏,但没有内存泄漏。该应用程序在模拟器中也运行良好。
What i have noticed is whenever i get a "Received memory warning", then "didReceiveMemoryWarning" method of every file in the project is called and then app crashes.
我注意到的是,每当我收到“收到的内存警告”时,就会调用项目中每个文件的“didReceiveMemoryWarning”方法,然后应用程序崩溃。
Any solution to this?
有什么解决办法吗?
采纳答案by Fonix
Well, to put it bluntly, you are just using too much memory. didReceiveMemoryWarning
gets called so that you can try free up some memory yourself so you dont crash the app (free up things that aren't in use that can be reloaded later).
好吧,坦率地说,你只是使用了太多的内存。didReceiveMemoryWarning
被调用,以便您可以尝试自己释放一些内存,这样您就不会使应用程序崩溃(释放可以稍后重新加载的未使用的东西)。
The simulator isn't accurate hardware wise when it comes to running apps, so i wouldnt always rely on it, and thats probably why you dont get the warning on the simulator.
在运行应用程序时,模拟器在硬件方面并不准确,所以我不会总是依赖它,这可能就是你没有在模拟器上收到警告的原因。
I cant really say what is causing your app to use so much memory from the information you have given
根据您提供的信息,我真的无法说出是什么导致您的应用程序使用了如此多的内存
回答by wesley
In ARC,the event(functionality) which create the received memory warning issue need to be inside @autoreleasepool{}
.Received memory warning issue might happens which overload from device memory.
在 ARC 中,创建接收到的内存警告问题的事件(功能)需要在内部。接收到的@autoreleasepool{}
内存警告问题可能会发生从设备内存过载。
回答by Monish Bansal
Check app by instrument-->memory allocation
通过仪器检查应用程序-->内存分配
it will show all memory using by app and if there will any leak it will show.
它将显示应用程序使用的所有内存,如果有任何泄漏,它将显示。
Are you using heavy images?
你在使用重图像吗?