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