iOS - i receive memory warnings but have no idea why - ios

I am developing for the iOS and checking my app with IPhone and 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.
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?

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.
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.

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.

Related

Memory Leaks Causes High Energy Impact For An iOS App?

I developed an app that communicates with multiple devices by socket connection. Once the app is running it searches for the devices and connects with them. Each connection is ran in a thread. I checked the memory when the app is running, it rises about 20+ Mb. I don't know if this is really high for an app, but the energy impact is very high.
I tried using the tools to check whether I am using too much heap memory or I have a lot of leaks. Well, the result is I do have a lot of leaks, but does this lead to very high energy impact? or there could be other reasons?
In some iPhones, the phone will overheat after running my app for awhile. Especially iPhone 7.

Get "Terminated due to Memory error" for ios 8 custom keyboard Extension

I am developing a ios 8 custom keyboard Extension. It run like a charm start.
But I always get "Receive Memory Warning" in Xcode. So my custom keyboard extension will suddenly terminate sometimes.
But I run the custom keyboard in its host app. There don't have any problem. Don't get "Receive Memory Warning" in Xcode. Don't terminate.
Anybody can help me? If app have any limit size for a Extension use?
Apple mentions in their App Extension Programming Guide that memory limits for app extensions are significantly lower than limits imposed on foreground apps. Additionally some types of extensions may have lower limits than others.
Apple is not explicit about these memory limits as far as I can tell and it's unclear if they are dependent on the device and how much memory other apps are consuming. But as Ethan mentioned, for keyboard extensions you should aim for less than 30MB to avoid crashing.
It's also important to test the extension when not running in Xcode or using a debug build configuration. It seems that the memory limits for debug builds are much higher.
iOS allocates less memory to extensions as they are supposed to be light and do one thing well. I suppose shall try limit memory use under 30mb...

iPad low memory warning, although no other apps are running, and my app allocates only 8 MB

I am receiving low memory warnings on the iPad (inspected via instruments) although no other apps are running, and my app has only 8 MB of live bytes.
In my understanding, iOS triggers memory warnings only, if the system is running out of resources. How can it be, that I still get them?
(To get a better understanding of the issue and the related circumstances, please check this question: Empty drawRect implementation causes memory warning)

What memory usage threshold when I receive memory warning in iOS

I did receive these warnings in my iOS app
Received memory warning. Level=1
Received memory warning. Level=2
The problem is, after Level=2 warning, my app will be killed...
How many MB of memory my app could use until I receive such warnings? I'm getting < 30Mb of "Live Bytes" in XCode Instruments before my app gets killed for level 2 memory warning. Is this my reading mistakes, or am I not suppose to use more than 30Mb of memory in my app?
I am testing using iPod Touch 4th Gen and iPhone 4, and targeting those devices as minimum.
Any advice are appreciated, and thanks in advance!
first of all I will ask myself what are you loading into memory that takes so much space. Second if you are releasing everything in the correct way. ARC simplify our lives but is not a garbage collector, there could be abandoned memory and other issues that makes memory grow. In iphone 3gs the limit of memory is about 25MB, when you reach it you get a memory warning, if your app is not able to flush some memory after that it will close.
If you want to support old devices like iPhone 3GS I would suggest not to exceed 12-15MB.

Tracing the root cause of low memory warnings

I see a lot of low memory warnings being issued when running my application in Instruments. The total memory allocation does not exceed 5.02 MB. What could be the reason? I checked the Leak Instrument as well. There I see leaks, but due to some framework classes. None are beacause of my project classes. How to trace the root cause?
Please see attached snapshots of Leaks & Allocation instruments:
Some versions of the OS on some iOS devices will send memory warnings to the foreground app when a background app (Mail, Messages, Music player, etc.) needs sufficiently more memory. This has nothing to do with the amount of memory your app is using. If your app is not using a lot of memory (well under 10MB), it can usually ignore these memory warnings, as the OS will usually kill a background app that is using more memory than your app instead of your app (no guarantee though, whether your app frees memory or not!).
If you want to avoid all these memory warnings when testing, put the device in Airplane mode and force quit all the background-aware apps in the multi-tasking bar before running your app.

Resources