Two settings for memory errors in iOS

Source: Internet
Author: User


1. Exc_bad_access Memory Error and nszombieenabled

Exc_bad_access is the most common error, which is usually caused by access to the freed memory address space. For example, if an object is already dealloc, this error will occur if you still send a message to this object. Because of this error, almost no useful information is displayed, we simply cannot determine where the program is wrong. Using the nszombieenabled environment variable can be a good solution to this problem.
Open your project, choose the menu "Product->edit Scheme" or the shortcut "commend+<"

The nszombieenabled environment variable causes the freed memory to continue to hold the object's information, and if we send a message to an already disposed object, we get an error message, and the program automatically breakpoints to the wrong location. If we send a description message to an already released UIButton object, we get the following message on the debug terminal:

At this point, the program will automatically break the breakpoint to "[UIButton description];" On this line of code.

2. Overrelease and Mallocstackloggingnocompact are appearing in the framework interior objects

By nszombieenabled environment variables, we can have many bugs. But sometimes the error occurs inside the framework, and the current stack of breakpoints is not in our code. Like what:

XXX: * * *-[calayer release]: message sent to deallocated instance 0xe250df0

This calayer is not created directly by us, and the release message does not occur in our code. We have no idea that this calayer is the view. So there is no way to make it clear that the class has problems. If you know where this calayer is alloc, then we need to Mallocstackloggingnocomp

The ACT environment variable. This environment variable opens the Alloc log, which records the stack when each object is Alloc. Based on the stack, we can figure out which class initialized the layer, and check the code to fix the problem. The Setup method is similar to nszombieenabled:

When message sent to deallocated instance messages are generated, enter in the Debug terminal:

Info malloc-history 0xe250df0
Will print the layer alloc when the stack, you can see the code call situation, find our own code, check the code and modify it.

Two settings for memory errors in iOS

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.