IOS 8: Zombie object with MRC debugging

Source: Internet
Author: User

Keyword: MRC manual reference count Zombie object nszombieenabled

Sunday in a group encountered a help code, the general situation is uitableviewcontroller initialization is normal, the application crashes when the downward stroke. The problem is anchored to the overridden Initwithstyle, where the other's code has an assignment statement: _name = name. This sentence directly uses the background storage variables, so did not go setter method. I look at the other side is the MRC code, opened the nszombieenabled only to confirm the problem, ashamed. Attach the key code and make a record.

. h file

@property (nonatomic, copy) Nsarray *name;

. m file

-(ID) Initwithstyle: (Uitableviewstyle) style {

// ...

_name = name; Bug points

Solution One

_name = [name copy];

Solution Two

Self.name = name;

// ...

}

Incidentally review the nszombieenabled logo. The nszombieenabled variable is used to debug memory-related issues and to track the release process of an object. The MRC era has a great effect, and the arc era, when it comes to object ownership, usually does not experience memory-related crashes. With nszombieenabled enabled, it replaces the default Dealloc implementation with a zombie implementation, which converts the object to a Zombie object when the reference count is 0 o'clock. The purpose of a zombie object is to send a message to it, which displays a log and automatically jumps to the debugger, which makes it easy to find the cause of the problem [1].

Reference:

[1]. Rob Napier is waiting for the American regiment to move the translation. iOS programming combat. BEIJING, People's post and telecommunications press. Page 262

IOS 8: Zombie object with MRC debugging

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.