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.
Related
It's not duplicate. My question is how to symbolicate crash error.
My live app is crashing and I've crash report in xCode and crashlytics but I don't have crashlog as it's happening on live app and it's random.
Is it possible to get some meaning out of crash report without a crash log?
How do we find out file & line number from such reports?
Here is one example of such crash
crash_info_entry_0
abort() called
crash_info_entry_1
myapp(569,0x16df57000) malloc: *** error for object 0x10404ddae: pointer being freed was not allocated
Symbolication is the process of translating addresses into symbols (functions, methods, etc). Without a crash log, which contains those addresses, symbolication doesn't make sense. You cannot translate addresses you do not have. But, where did the output you listed come from? It looks like it could be part of a larger log. You've tagged the issue Crashlytics - did this report come from their service?
There's some helpful information in the logging you've included. The good news is that it is telling you that you've got heap corruption. malloc has called abort because it's detected an inconsistency with its internal structures. Further, it's extremely unlikely that a symbolicated stack trace would help you, because heap corruption is rarely, if ever, caused by functions further up the stack.
Keep in mind that the crash you are seeing here is an effect. To fix this issue, you need a cause, and a stack trace isn't going to get you that in this situation.
There's more bad news. It is hard, and often even impossible, to reason about heap corruption. Replicating the bug can also be impossible, as memory corruption is typically not deterministic. As you've noted, the crash appears random. That's because it probably is.
What I would recommend doing here is using the various tools that Apple provides to help debug this kind of issue.
Look for other crashes that look heap-corruption-related
Try out Zombies in Instruments
Try malloc scribble, or guardmalloc, two other good memory debugging tools
It is extremely common for one heap-corrupting bug to cause lots of different kinds of crashes. This could be an objc over-release, so I'd also keep my eye out for selectorNotRecognized exceptions. Those crashes might give you more of a clue as to what kind of object is being over-released.
Good luck!
Facing this strange issue where my app crashes after certain period of time. Attached is the screenshot from the Crashlytics as well.
This has occurred in an iPhone 6Plus running iOS 11.4.1.
I'd like to see a full crash log to get more information. With anything related to concurrency, I like to take a look at what all the threads are doing. Sometimes there is a clue in a thread that did not crash.
I do not know what's going on. But I can make an educated guess here that you are seeing heap corruption of some kind. The function "os_unfair_lock_corruption_abort" strongly indicates that the OS's primitive locking mechanism has detected a corrupted data structure, and is killing the processing.
Heap corruption is super-common, and can be extremely difficult to debug. One of the reasons is what you are seeing here is a symptom of the corruption, not the source. The source could be completely unrelated to locking/OperationQueue internals.
My suggestions would be to try out the memory debugging tools at your disposal, and attempt to fix all issues you can find. You might never be able to know which, if any, cause this. But, that's pretty much all you can do.
Check out malloc scribble, guardmalloc, and even NSZombies. All could potentially turn up some heap corruption bugs that are in your code.
We have some very random bugs happening and throwing EXC_BAD_ACCESS, or malloc_error_break, or abort. There is no consistency to the exceptions, and enabling NSZombies doesn't cause any zombies to be triggered ever.
In fact, running with zombies enabled causes the crashes never to occur. I believe there is a subtle memory error in this codebase, and after spending many hours cleaning up what could be minor issues, we still have not solved the issue.
It make sense that a bad pointer may be overwriting a piece of memory, which is then later dereferenced and crashes the app. But what are other ways to isolate the underlying issue?
We have used all the diagnostic memory tools which will run with the device attached as well (this application uses a peripheral, so cannot be fully debugged in the simulator).
NSZombie is just a mechanism to poison space used by objects instead of freeing them, similar to Address Sanitizer's Memory Poisoning. By using various instrumentation such as NSZombie or the above mentioned ASAN, your stack and heap allocation will be laid out differently, leading to undefined behavior in a condition where a crash would likely be the best case scenario.
EXC_BAD_ACCESS means you tried to access an invalid address or tried to read or write to a memory region you do not have such permissions for. The inconsistencies you're running into are likely consequences of a nasty stack or heap corruption, like sometimes overwriting a variable that just holds data and sometimes overwriting a pointer being used by the program.
Data layout matters a lot for what happens and heap layout is often randomized in non-debug builds which adds even more room for inconsistent crashes. In addition any changes to program source code or build settings may/will inevitably cause data layout changes.
I would recommend:
Build in debug mode (-g compiler flag) and run with debugger attached. When you get a crash, gdb or lldb (the latter being the default for Xcode tooling) will stop execution and let you do things, from there get a stack trace using bt and that may let you work out the deeper cause of the problem.
Use ASAN, this page explains about its usage within Xcode tooling. It's generally an excellent tool for dealing with memory issues. Beware that using it with shared libraries built without support for it may cause anomalies but it usually tells you of them and generally tries to hold your hand as much as it can.
"printf debugging" can help, something like #define TRACE printf("%s %s:%d\n", __func__, __FILE__, __LINE__); and scattering these across the likely problem point can actually be helpful.
In general, I would suggest using a debugger first, without NSZombie or anything, just do a bunch of runs to a point of a crash and get stack traces, register states etc. Having those samples across multiple crashes can help you narrow down the problem.
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)
So I'm trying to get my first app ready to submit to the app store, and I'm at the profiling/analysis stage of it. My app is crashing, and I have some questions I can't seem to dig up answers to.
I've been running my app through Instruments checking allocations and leaks, and it's been crashing fairly regularly. The weird part is that allocations says my total is only 2-3MB, and while I do have a leak, Instruments shows only an occasional ~300 bytes (about once every 2-3 minutes with heavy use), but I'm still getting low memory errors and signal:9 killed:9 when it crashes.
Are there things that Allocations isn't showing me? (i.e. storyboard initialized views, or memory allocated on background threads)
How significant a problem is my small leak? I'm obviously working to stamp it out, but is it likely that this is just a red herring? Or could it be the cause of my crashes?
I did some HeapShot analysis (credit goes to bbum for the awesome walkthrough) and found two instances where I WAS in fact leaking memory, just in a way that wasn't being captured by the Leaks instrument.
App's been running steadily through a few more days of testing, so it seems alright now.