开发者

Keeping mutiple apps in background in iPad causes memory issue?

开发者 https://www.devze.com 2023-04-05 01:09 出处:网络
I am developing an app for the iPad and I realized that my App is receiving memory waring even for small duration of usage.

I am developing an app for the iPad and I realized that my App is receiving memory waring even for small duration of usage.

I checked in Instruments and saw that the App was crashing at memory allocations of as low as 6MB.

I had multiple apps kept open in the background.

When all 开发者_StackOverflowthe background applications were closed, the app seemed to work fine.

So, does it mean that multiple applications in the background cause memory issues?

Thanks in advance :)


No. In low memory situations iOS kills apps that are in the background, so their presence when you start your app is not, in itself, a problem.

The problem is that when you get a low memory warning you either ignore it or don't release enough memory to "convince" the OS that everything is okay.

Edit to cover the questions in your comment:

If I launch multiple apps why do the apps seem to go slower?

Remember that iOS does not have swap space. If you have multiple apps loaded then they will use memory, memory that you can't use to cache stuff. When applications go into the background they are supposed to release as much memory as possible. Some are better at this than others.

It's also worth noting that apps in the background are killed to make space for the foreground app.

Or crash sooner over prolonged usage?

Apps that crash have bugs. It's as simple as that.

And what explains the bizarre memory warnings for allocations as low as 6Mb???

Think about it: iOS can't send you a memory warning after all memory has been depleted. It's too late by then.

Instead it has to use heuristics. Usually the heuristics work. The foreground app releases some of its cached data, maybe one or more background processes are killed. This allows the foreground process to continue without crashing.

So things can go wrong if you ignore the warnings.

Or the heuristic could be getting it wrong.

But either way it's moot. This is how iOS works. You can't manually kill other processes. You can't suggest users reboot their handset before running your app (Apple will likely reject it). All you can do is respond appropriately to the low memory warning, whether that comes after you've allocated 6Mb or 60Mb.

0

精彩评论

暂无评论...
验证码 换一张
取 消