First, iOS common crash problem
1. Inserting empty elements
For variable objects such as Nsmutablearray, Nsmutabledictionary, Nsmutableset, and so on, when inserting an empty element crash
The correct approach is to add a judgment, sample code is as follows:
Nsdictionary *dic;
Nsmutablearray *arr=[nsmutablearray New];
if (DIC) {
[Arr Addobject:dic];
}
NSLog (@ "%@", arr);
Add non-NULL condition: if (DIC)
2. Cross-border and pointer null judgment
This crash is similar to C + +, for objects of type Nsarray, when calling Objectatindex, be sure to determine whether they are out of bounds.
The pointer oc is not used much in development, if you want to use it, you must also determine whether it is empty
3, after adding nsnotification, in the Dealloc function, must be removeobserve
4, create Nstimer Scheduled Tasks, in the Dealloc function, must be invalidate
5, when you launched a network request in the code, and set the proxy, then in the Dealloc function must release the change agent, because the network access is time, when the network data back to find the proxy object is not, this time will occur crash
6, use the high version of the API, because each app has the use of the iphone version, when the user machine is using the lower version of the system, if you encounter the high version of the API will certainly crash
7, take up too much memory, after receiving two times memory warning will be crash, so the release of Things must be released in time
8, multi-threaded concurrency caused by the crash, in a multi-concurrency environment, if a thread has deleted data, another thread to access, because the data is not necessarily crash, so must be through the locking mechanism to solve the problem
9. Call a class or method that does not exist
if (nsclassfromstring (@ "Mfmailcomposeviewcontroller")) Respondstoselector:
Common crash problems in iOS and crash log analysis