Xcode debug exc_bad_access and message sent to deallocated instance

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.