我是C,Obj-C和iPhone的初學者,我正在嘗試使用很多術語,希望你們能幫助解決問題。現在已經掙扎了幾天在iPhone上泄漏內存:(
我的代碼是調用一個包含一個搜索字段和一個表的nib的方法,該表從下面爲'theList'創建的數組的搜索中填充。使用'儀器',我得到一個泄漏線: NSDictionary * theItem = [NSDictionary dictionaryWithObjectsAndKeys:clientName,@「Name」,clientId,@「Id」,nil];,但我不明白爲什麼: (
我知道這可能是一個難以回答的問題,但如果有的話可以有任何幫助!
- (void)editClient:(id)sender {
if (pickList == nil) {
pickList = [[PickFromListViewController alloc] initWithNibName:@"PickList" bundle:nil];
}
TimeLogAppDelegate *appDelegate = (TimeLogAppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableArray *theList = [[NSMutableArray alloc] init];
int i;
for (i=0;i < [appDelegate.clients count];i++) {
Client *thisClient = [appDelegate.clients objectAtIndex:i];
NSString *clientName = [[NSString alloc] initWithString: thisClient.clientsName];
NSNumber *clientId = [[NSNumber alloc] init];
clientId = [NSNumber numberWithInt:thisClient.clientsId];
NSDictionary *theItem = [NSDictionary dictionaryWithObjectsAndKeys:clientName,@"Name",clientId,@"Id",nil];
[theList addObject:theItem];
theItem = nil;
[clientName release];
[clientId release];
}
[pickList createSearchItems:theList :NSLocalizedString(@"Client",nil)];
[theList release];
appDelegate.returningID = [NSNumber numberWithInt: projectsClientsId];
[self.navigationController pushViewController:pickList animated:YES];
}
提前感謝!
謝謝你的時間!我確實按照你的建議使用了它,但改變了代碼,認爲它可以解決問題。現在它按照你的建議回來了,但是泄漏結果相同。我能否認爲問題出在被調用的筆尖之內? – Chris 2009-06-08 07:52:25