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