我有一個問題。將對象設置爲零時,不會調用dealloc方法
我首先創建了一個擴展NSObject的對象,我提供了覆蓋描述和dealloc方法。這是我的Employee.m文件:
@implementation Employee
.....
-(NSString *)description
{
return [NSString stringWithFormat:@"Employ ID: %d has $%d value of assets", [self employeeID], [self valueOfAssets]];
}
-(void)dealloc
{
NSLog(@"deallocating.. %@", self);
[super dealloc];
}
在我的main.m,我首先創建一個NSMutableArray保存Employee對象的列表:
NSMutableArray *employees = [[NSMutableArray alloc] init];
for (int i =0; i< 10; i++)
{
// Create an instance of Employee
Employee *person = [[Employee alloc] init];
// Give the instance varaible interesting values
[person setEmployeeID:i];
[employees addObject: person];
}
,並在年底我設置員工零
employees = nil;
我預計要調用的每個Employee對象的dealloc
方法,我會看到一些日誌,如:
deallocating.. Employ ID 0 has value.....
deallocating.. Employ ID 2 has value.....
....
但是,我沒有看到任何日誌,並且如果我在dealloc
方法上設置斷點,斷點永遠不會被命中。
有什麼想法?
問題已經通過將我的項目解決到ARC:編輯>重構>轉換爲Objective-C ARC,以獲取有關ARC的更多信息http://developer.apple.com/library/ios/#documentation/DeveloperTools/Conceptual/WhatsNewXcode/Articles/xcode_4_2.html –