我使用导航控制器在rootView上推送和弹出addColorView。根据泄漏工具,一些对象在推出视图时泄漏(三个Mutable数组和两个可变字典),并带有一个负责的框架[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;
}