이 코드의 분석 실행시 "잠재적 인 누수"메시지가 표시된다. . 단순한 UINavigationController가 /의 TableView 비트)"잠재적 누설 오류"- 그러나 나는 그것을 볼 수 없다.
내가 얻을 전체 메시지는 다음과 같습니다
그것은 나에게 이해가되지 않습니다 " 'tempKey'할당에 저장된 객체의 잠재적 인 누출"- 누구나 볼 수 있습니다 그것?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// create a tempKey String var, which will store the clicked-artist's name
// -- this here is the line the compiler says the error is in:
NSString *tempKey = [[NSString alloc] init];
if ([ArtisticStaffNames objectAtIndex:indexPath.row] == @"Jeff Smith")
tempKey = @"Jeff";
else if ([ArtisticStaffNames objectAtIndex:indexPath.row] == @"Dan Jones")
tempKey = @"Dan";
else if ([ArtisticStaffNames objectAtIndex:indexPath.row] == @"Matt Low")
tempKey = @"Mat";
else if ([ArtisticStaffNames objectAtIndex:indexPath.row] == @"Lisa Jennings")
tempKey = @"Lis";
else if ([ArtisticStaffNames objectAtIndex:indexPath.row] == @"Michael Bluarique")
tempKey = @"Mike";
artisticStaffDetailVC *artStaffVC = [[artisticStaffDetailVC alloc] initWithNibName: @"artisticStaffDetailVC" bundle:nil];
artStaffVC.key = tempKey;
[tempKey release];
// Sets the text of the BACK button on next screen to "back":
// alloc a UIBarButtonItem:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] init];
backButton.title = @"Staff";
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
// Pushes the next view/screen on:
[self.navigationController pushViewController:artStaffVC animated:YES];
[artStaffVC.key release];
}
음 '단순히' 'tempKey'를 'alloc'ing하지 않고 선언 해 보았습니다. (의미 : 'NSString * tempKey;'- 'alloc'또는 'init'없음.)하지만 몇 줄 후에 'artStaffVC.key = tempKey;' "할당 된 값은 가비지 또는 정의되지 않았습니다."라는 메시지가 나타납니다. 그래서 나는 이것이 올바른 접근법이 아니라고 생각합니다. 그래서 .... 어떻게 해결할 수 있을까요? 이 작업을 수행하는 올바른 방법은 무엇입니까? – sirab333
@ sirab333이라면 포인터를 단순히 선언하는 대신 nil로 초기화하는 것이 가장 좋습니다. 이것은 할당하지 않고 문자열을 사용하려고하면 이론적으로'EXC_BAD_ACCESS'를 막을 것입니다. NSString * tempKey = [[NSString alloc] init]; 대신'NSString * tempKey = nil;'을 사용하십시오. –
그게 효과가! :-) 이제는 왜, 어떻게 :-) 도움을 주셔서 감사합니다. – sirab333