NSZombieEnabled: Let me debug again until three o'clock in the middle of the night

Source: Internet
Author: User

Recently, this project is using ARC. When tracking the memory, it is found that the memory is incorrect.
In this case, the dealloc method will not be called:
@ Interface Obj1: NSObject
{
Obj2 * obj2;
}
 
@ Interface Obj2: NSObject
{
}
 
@ Implementation Obj1
 
-(Void) dealloc
{
// Obj2 = nil; // <--- This is needed to get obj2 to be dealloc 'd.
NSLog (@ "Obj1 dealloc ");
}
 
-(Id) init
{
If (self = [super init]) = nil)
Return nil;
 
Obj2 = [[Obj2 alloc] init];
 
Return self;
}
 
@ End
 
@ Implementation Obj2
 
-(Void) dealloc
{
NSLog (@ "Obj2 dealloc ");
}
 
-(Id) init
{
If (self = [super init]) = nil)
Return nil;
 
Return self;
}
 
@ End

If the dealloc of obj1 is broken, the call to dealloc of obj2 is also broken, but it will not be broken in any case. At first, I added obj2 = nil to the dealloc of obj1 to reclaim the memory. However, this function is available in ARC and does not need to be added. The code is okay. check settings (after several hours) have been completed. NSZombieEnabled was enabled. The sweat is exhausted, and the loss of NSZombieEnabled was suffered last time. This time it was planted again. However, I finally found the reason, but I did nothing in the past few hours, and only had a long experience.

 


From happy Program

Related Article

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.