我有一個顯示儀器泄漏的代碼。它顯示了泄漏,我初始化arrayDetPerformance
與arrayDetail
內存泄漏:在iPhone應用程序中釋放NSArray的問題
的內容,如果我鬆開我的arrayDetail
那麼我的應用程序崩潰。
什麼可能是錯的?
下面是代碼:
NSDictionary *finalResult = [extractUsers JSONValue];
// NSLog(@" Stamp-16 : %@",[NSDate date]);
NSLog(@"Array2 : %d",[arrayDetail retainCount]); //RETAIN COUNT IS 0
arrayDetail = [[finalResult objectForKey:@"Detail"]
NSLog(@"Array2 : %d",[arrayDetail retainCount]); //RETAIN COUNT IS 2
// NSLog(@"Data is : %@",array1);
// NSLog(@" Stamp-17 : %@",[NSDate date]);
//NSLog(@"Final Value is : %@",[[allUsers objectAtIndex:0] valueForKey:@"password"]);
//[self setUserData:allUsers];
//[tblView reloadData];
[responseString release];
[request release];
}
//sleep(0.3);
//[inProgressIndicator stopAnimating];
[fileContents release];
//Release all the allocated data
[json release];
//label.text = @"Finish";
// NSLog(@" Stamp-19 : %@",[NSDate date]);
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
//NSLog(@"Array2 : %d",[array2 retainCount]);
arrayDetPerformance = [[NSMutableArray alloc] initWithArray:arrayDetail];
chartPoints= [arrayDetPerformance valueForKey:@"Points"];
NSLog(@"Chart Points: %@",chartPoints);
[def setObject:chartPoints forKey:@"yarray"];
[def setObject:@"YES" forKey:@"flagThumb"];
//array1 = [[NSMutableArray alloc] initWithObjects:@"New",@"Table",@"View",nil];
//[self.Dettable reloadData];
//sNSFileManager *fileManager = [NSFileManager defaultManager];
//[array2 release];
NSLog(@"ArrayDEtPerfomance : %d",[arrayDetPerformance retainCount]);
NSLog(@"array2 : %d",[arrayDetail retainCount]);
if([chartPoints count]>0)
{
PlotItem *plotItem = [[PlotGallery sharedPlotGallery] objectAtIndex:0];
[plotItem imageHive:Fund];
}
//[arrayDetail release];
}
內存泄漏是在
arrayDetPerformance = [[NSMutableArray alloc] initWithArray:arrayDetail];
另外我對爲什麼從0直接轉到2在下面的代碼保留計數困惑線圖所示:
NSLog(@"Array2 : %d",[arrayDetail retainCount]); //RETAIN COUNT IS 0
arrayDetail = [[finalResult objectForKey:@"Detail"]
NSLog(@"Array2 : %d",[arrayDetail retainCount]); //RETAIN COUNT IS 2
什麼可能是錯的?
如何聲明'arrayDetPerformance'?這是一個財產嗎? – 2011-04-15 10:45:04
方面評論:AFAIK你不應該在運行時依賴[yourObj retainCount]值...保留計數只能在樂器中有用。 – matm 2011-04-15 10:48:49
@Nick Weaver:是的,它是一個帶有屬性(非原子,保留)的NSMutableArray並被合成。什麼可能是錯的? – 2011-04-15 11:04:50