我使用导航控制器在 rootView 上推送和弹出 addColorView。根据 Leaks 工具,当视图被推送时(三个可变数组和两个可变字典)带有一个负责任的框架 [UITableView _setupTableViewCommon] 当这个视图被弹出时,另外两个对象被泄露(UIGobblerGestureRecognizer 对象和一个可变数组)
- (void) addButtonPressed {
NSLog(@"addButtonPressed");
AddColorViewController *addColorViewController = [[[AddColorViewController alloc] init] autorelease];
[self.navigationController pushViewController:addColorViewController animated:YES]; // <-- The Leaks tool points right here
}
问题是我应该在哪里寻找实际的泄漏?UIGobblerGestureRecognizer 到底是什么?
编辑 1:AddColorViewController.m 中的 viewDidLoad 方法:
- (void)viewDidLoad
{
[super viewDidLoad];
self.listOfLabels = [[[NSArray alloc] initWithObjects:@"Name", @"Red", @"Green", @"Blue", nil] autorelease];
self.navigationItem.title = @"New";
[self.tableView initWithFrame:self.view.frame style:UITableViewStyleGrouped];
UIBarButtonItem *homeButton = [[UIBarButtonItem alloc] initWithTitle:@"Home" style:UIBarButtonItemStylePlain target: self action:@selector(homeButtonPressed)];
UIBarButtonItem *saveButton = [[UIBarButtonItem alloc] initWithTitle:@"Save" style:UIBarButtonItemStylePlain target:self action:@selector(saveButtonPressed)];
self.navigationItem.leftBarButtonItem = homeButton;
self.navigationItem.rightBarButtonItem = saveButton;
[homeButton release];
[saveButton release];
}
...
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryNone;
UITextField *textField = [[UITextField alloc] init];
if ([indexPath row] == 0) {
textField.frame = CGRectMake(220, 10, 170, 30);
textField.placeholder = @"color";
textField.keyboardType = UIKeyboardTypeDefault;
}
else {
textField.frame = CGRectMake(220, 10, 80, 30);
textField.placeholder = @"0..255";
textField.keyboardType = UIKeyboardTypeNumberPad;
}
textField.delegate = self;
textField.tag = [indexPath row] + 1;
textField.adjustsFontSizeToFitWidth = YES;
textField.textColor = [UIColor blackColor];
textField.textAlignment = UITextAlignmentLeft;
[cell addSubview:textField];
[textField release];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = [self.listOfLabels objectAtIndex:indexPath.row];
return cell;
}