If a exc_bad_access error occurs, it is basically due to a memory leak, an error release, and a release operation on an already freed object. But Xcode does not sometimes tell you where the error is (Visual Studio does it well). However, we can view the source of the error by setting the XCODE environment variable environment variable nszombieenabled,mallocstacklogging:
1, Menu Product > Manage schemes;
2, check the current scheme, click the Edit button;
3. Set environment variables. In arguments > Environment Variables;
4, add environment variable mallocstacklogging,nsautoreleasefreedobjectcheckenabled,mallocstackloggingnocompact, Nszombieenabled and set Yes
5. Finally remember to delete or set the environment variables as no, because they will make the memory not be released.
Message sent to deallocated instance will have a memory address, such as: 0x6497860, we need to see the address of malloc history. View the method, under the original GDB, using the "info malloc_ History 0x6497860 "to display malloc records. But the new version of Xcode no longer support, how to do? Xiu-tease sacks, we also have terminal, using terminal malloc_history commands such as "Malloc_history 32009 0x6497860" or "sudo malloc_ History 32009 0x6497860 "can be displayed. 32009 of these are the PID of the process, which, based on this malloc record, can roughly locate the code location of the error message.
A code similar to the following will appear, which prompts you to find the exact location of the error
0xfcdff50-0xfce00b7 [size=]: thread_3bf2a28 |start | Main | Uiapplicationmain | | Gseventrunmodal | Cfrunloopruninmode | cfrunlooprunspecific | __cfrunlooprun | | __cfrunloop_is_calling_out_to_an_observer_callback_function__ | _aftercacommithandler | | ___aftercacommithandler_block_invoke | __38-[uitableview Touchesended:withevent:]_block_invoke | -[uitableview _ Userselectrowatpendingselectionindexpath:] | -[uitableview _selectrowatindexpath:animated:scrollposition:notifydelegate:] | -[messagelistviewcontroller Tableview:didselectrowatindexpath:] | _objc_rootalloc | Class_createinstance | Calloc | Malloc_zone_calloc