Memory issue warning in my app, but app doesn't consume a lot memory - ios

I get an lowmemory waring in my app and then it crashes.
But when I look into the memory consumption, I can't recognize any memory limits of my app. I also can't see any crashlogs on my device.
Does someone has a hint for me ?
in my didReceiveMemoryWarning I set a breakpoint.
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
print("memory low received !!!");
}
then i checked the memory and it looks like following:
UPDATE
I know already what are memory leaks, so it doesn't help to give me hints in general. I am interested to know if I read the memory usage correctly and if we can see that the problem is the app or the general invironment.
I run my app several times and do always the same actions (automated by code) and from 5 times it crashes one time.

The low memory warning can be caused for a lot of reasons. If you see that your application is not using too much memory and if does not crash due to the memory usage then there is no issue.
But generally I believe 3 things can trigger the warning:
Your application is using too much memory (does not seem to be the case)
You have other applications opened that consume most of your memory which will be killed by the OS on warning (probably your case)
Your application memory consumption keeps jumping up and down which should be avoided and the OS may kill your app in this situation (I hope you are not doing something that could produce this)

Related

What can cause "Message from debugger: Terminated due to memory issue"

My app is sometimes crashing and the console says
Message from debugger: Terminated due to memory issue
Has anyone else experienced this and know some of what can cause this? Here is what I have tried so far.
I have enabled Zombie Objects and it does not find anything.
This only happens on my iPhone and so I can't run the other Memory Management tools that only run on the simulator (ie Guard Malloc).
This only happens after a low memory warning. It doesn't happen after every memory warning, just after some memory warnings. When my app receives a memory warning, it clears out a number of caches and so my guess is that it is related to this.
In the simulator I simulated memory warnings and this never happened.
I thought that it might be related to a weak object so I added a symbolic break point on objc_weak_error. I did get the debugger to stop one this break point once and I fixed the weak error, but it did not fix the "Terminated due to memory issue".
I though that maybe I wasn't freeing up enough memory, so I watched the total memory used by my app in Xcode and it never went over 50% of available memory.
My app is a mixture of Objective-C and Swift code. It appears that this is coming from areas of my app that are written in Objective-C, but I am not 100% sure.
I would love to know if anyone else has experienced this issue and if so what you did to fix it. I have looked at the other Stack Overlow issues on this and so far none of them have given me any extra insight to this problem.
So one of my initial observations was wrong. I thought that my app never went above 50% of available memory (point 6 above). I was wrong. It did use up more memory and this error is coming because I did not release enough memory during the memory warning.

Retrieve memory iPad information in iOS app

Is there a way to retrieve information about the memory of the ipad during running?
For example, i would like to print in the console the use of memory at t instant.
Thanks
You should instrument this instead of trying to print a number. That number is not really useful. What you care about is your application's dirty memory footprint for memory pressure on the device and how much code/mapped ro mem you're evicting to see if you're essentially thrashing and causing performance problems due to memory pressure.
The other info you can get, like device inboard memory and how many pages your app has allocated are not useful because you don't know how much of that memory is wired to other devices or the kernel and you don't know how many of your allocated pages are faults at that point.

iOS, check if the app crashes because of lack of memory

How can I make sure that reason of crashes is lack of memory?
Is there anything specific in crash log?
Maybe I have to use some tools or libraries?
UPDATE: my app uses lot of memory and receives memory warnings. It's very difficult to reduce memory usage. It crashes because of memory warnings time to time. But I want to make sure that it doesn't crash because of other reasons.
So how can I check the reason of app crash (it receives lots of memory warnings every time)
UPDATE2: Application has lots of 3D graphics and complex UI that takes lots of memory for textures. Customer doesn't want to make any kind of "loading..." pauses. If I unload invisible textures in background I can't get smooth animations.
So I just need to detect is there any crash reasons except memory.
At least you could implement the method
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
in your app delegate, and put a log to see if this indeed you are going through it before crashing.
Product -> Profile -> leak is a possible method to check memory leak. Allocations will show the total memory being used, and leaks will show leaks due to not releasing.
how-to-debug-memory-leaks-with-xcode-and-instruments-tutorial
that is a useful tutorial
You can use Apple's Instruments Tool to profile various things such as memory usage. This tool is bundled together with Xcode.

iPhone memory warnings and crashes - but Instruments showing lowish memory use

I have a strange memory issue I'm having problems resolving and would appreciate some advice as to where else to look.
The program I have (iPhone App) has a function whereby it basically downloads loads of files, processes those that are JSON, and stores the rest to disk. The JSON processing is CPU intensive and can take several seconds per file, so I have a NSOperationQueue with maxConcurrency limited to 1 that handles all the heavy lifting, and a queue that manages the multiple files to download.
Ever since iOS5 came out, the App has had problems completing the download sequence without crashing and so far what I have tried is;
1) Changed the performSelectorOnBackgroundThread JSON processing to use a single NSOperationQueue so as to limit the number of background threads working with large objects.
2) Added NSAutoReleasePools inside loops that create multiple, large, transient objects.
3) Flushed the sharedURLCache to ensure the files aren't hanging around in the system cache.
4) Stored the JSON objects to disk using NSKeyedArchiver and passed the filenames between threads rather than the actual objects, to again try to mitigate the number and size of retained objects currently in use.
All of these at first seemed to make a difference, and when I look at the memory allocations, I've now got the peak usage down from just over 20MB (hence no wonder it was crashing) to under 10MB, and yet the app is still crashing with low memory as before.
I'm trying to trace what is eating the memory causing the app to crash and on this occasion I'm having real problems persuading Instruments to tell me anything useful.
Here's a typical trace (on an iPhone 3GS running iOS 4.3.5)
You can see that the PEAK usage was a tad over 7MB and yet shortly after, you can see the 2 flags pertaining to low memory, and then low memory urgent, followed by the app terminating shortly thereafter.
If I use the memory monitor, the cause of the crash seems clear enough - physical memory is being exhausted - look at the light green trace below. The low memory warnings co-incide (not surprisingly) with the physical memory running out.
There are no leaks showing FWIW either (I've done that in other runs).
It's not image caches or NSURLConnection caches and the only thing I can think of is that perhaps there are some bad leaks that aren't being detected ... but I'm having issues identifying them because if I click into all allocations to see the objects that are live, and then do a command-A to select them all (in order to paste them into a spreadsheet to see where the memory seems to be), at the point I hit command-C to copy them, Instruments beachballs and never recovers.
I really cant figure out what's going on. Does anyone have some advice on how to persuade instruments to show me some more useful information about what is using this memory?
Sorry I can't post any meaningful code fragments ... hopefully the instruments screenshots at least give you an idea about where I'm coming from.
The Leaks instrument isn't terribly useful for figuring out anything but the obvious leaks in your app.
What you are describing is an ideal candidate for heapshot analysis.
tl;dr Heapshot analysis allows you to see exactly how the heap of your application grows between any two points of time (where you determine the points).

ipad application memory warning when using little memory

I am running an ipad application compiled for release and am seing memory warnings once in a while.
When I run the app on the device and connect Instruments, I see that the app never passes 40MB of real memory, but the warnings are still occurring.
What might be causing this? How can I better track down the reason?
40 MB of real memory is a lot, for an iPad. Even if it was not, the system will deliver the low-memory warning to you from time to time anyway, without your application being the main culprit. Tracking down precise memory usage in your application is sometimes hard, I’d suggest to spend some time with the Object Allocation instrument while working with the app. If you are not getting killed and you are sure that you do not leak the memory, you can also simply ignore the warnings.
40MB is high for the iPad considering it only has 256MB to start with. There could be other applications holding on to memory which will be killed off as more memory is needed. Just make sure you aren't leaking anything. Also use NSAutoReleasePools where applicable to reduce peak memory usage in memory intensive loops.

Resources