EXC_BAD_ACCESS
What is EXC_BAD_ACCESS?
EXC_BAD_ACCESS means, When we are accessing a bad memory this exception thrown from the runtime. During that time the application will be crashed that means app suddenly exit without any notifications.
The root cause for this error or crash is, accessing a deallocated or invalid memory address in our app. If you are seeing this crash in your crash logs, sometimes this makes frustration to the developers.
How we solve this?
The main problem is reproducing the crash is not an easy one. It's hard to reproduce this crash.
If you know the exact reason or where this happened that time we easily fix these crashes.
How to reproduce the crash?
As I said, reproducing this crash is not an easy job. If you have a crash log analysis and check out code flow to find a reproducing scenario. Sometimes this crash is occurred due to multiple threads accessing a single object at a time. This is also called as 'Race Condition'.
What are all the tools used to debug this?
Xcode provides some tools to debug this kind of issue.
1. Address sanitizer
2. Zombie object.
How to use Address Sanitizer?
Address Sanitizer is a tool that is provided by Xcode. This is Also called ASan. This tool is used to find the memory-related runtime issues. We are using this for our development profile only. Apple also recommends this. Once you enabled this in your app Scheme, and run your app normally. If any memory-related issues raised ASan will notify you.
For more details about ASan: https://developer.apple.com/videos/play/wwdc2015/413/
What are the Zombie Objects?
If you are sending a message to a deallocated object, that deallocated object receives that message. This deallocated object is called Zombie Object.
How to determine this crash due to Zombie?
In your crash logs if you are seeing Objc_msgSend, Objc_retain, Objc_release those messages are shown we have a Zombie object in our app.
Fixing the Crash due to Zombie Object?
We can check the zombie object in 2 ways,
1. By Instruments
2. NSZombieEnabled in Scheme.
Both raise a flag if any zombie objects they found.
Finding Zombie object by Instruments: https://help.apple.com/instruments/mac/current/#/dev612e6956
If we want to analyze the crash: https://developer.apple.com/documentation/xcode/diagnosing_issues_using_crash_reports_and_device_logs/identifying_the_cause_of_common_crashes?language=objc
Happy Coding...!
No comments:
Post a Comment