Updated 26 November 2021
In this blog, we will see what is EXC_BAD_ACCESS in swift. Basically, it is an exception that occurs due to bad access of memory. The reason for that exception can be different. The exception may occur when memory is deallocated while the pointer is still pointing that memory then, in that case, it becomes a dangling pointer and if we access that pointer then our app will crash. The memory access problem can also occur because of writing to read-only memory or jumping to instruction at an invalid address.
It looks as follows
1 2 |
Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000 |
1 2 |
Exception Type: SIGSEGV Exception Codes: SEGV_MAPERR at 0x41e0af0c5ab8 |
Reproducing and solving EXC_BAD_ACCESS exception
It is sometimes quite difficult to reproduce the exception. you may try the same configuration like using the same device, OS, and version to reproduce the crash. You can also use firebase Crashlytics which will be useful to reproduce the exception.
You can also use Xcode tools to check the memory issue in your app.
Address Sanitizer
It is an Xcode tool that can be used to find the memory issue in the app at the run time. Whenever it finds any memory issue then it pauses the app and you verify the issue. You can enable it from the edit scheme option from your Xcode.
Thread Sanitizer
You can enable this option from the scheme configuration. This helps to find that the app does not contain any thread issue which causes the memory issue. Thread issue causes Data races. Data races occur when the same memory is accessed by multiple threads without synchronization and at least one access is written access.
Thanks for reading this blog.
You can also check other blogs from here. If you have any issues, query or suggestions then you can leave your issues/query/suggestion in the comment section.
If you have more details or questions, you can reply to the received confirmation email.
Back to Home
Be the first to comment.