2010-10-07 80 views
0

我有一個正常工作的程序。然後我從http://github.com/matej/MBProgressHUD下載了一些代碼,在做某事時顯示進度計。從NSMutableArray到NSData的對象更改爲NSString

這是使進度計彈出的代碼。該方法myTask運行時

[HUD showWhileExecuting:@selector(myTask) onTarget:self withObject:nil animated:YES]; 

這將顯示一個進度條。

這是showWhileExecuting方法的代碼。

- (void)showWhileExecuting:(SEL)method onTarget:(id)target withObject:(id)object animated:(BOOL)animated { 

    methodForExecution = method; 
    targetForExecution = [target retain]; 
    objectForExecution = [object retain]; 

    // Launch execution in new thread 
    taskInProgress = YES; 
    [NSThread detachNewThreadSelector:@selector(launchExecution) toTarget:self withObject:nil]; 

    // Show HUD view 
    [self show:animated]; 
} 

如果我用這個來調用函數myTask然後我的類屬性的人會從NSMutableString某處更改爲NSData對象,然後以後它將改變一個NSString。我沒有看到代碼中的任何地方導致這個改變,所以它可能是某種錯誤。內存是否損壞?是什麼導致了這種情況發生?

回答

3

很可能是內存(保留/釋放問題)。如果你沒有妥善保留一個物體,它可能會從你的下面釋放出來。此時,內存將被操作系統收回,該操作系統可能決定在那裏存儲其他內容。嘗試打開NSZombies,並仔細檢查你的保留/釋放/自動釋放。

+0

當我打開NSZombies時,我可以看到對象變成了NSZombie NSArray。 – 2010-10-07 17:38:34