我的很多内存泄露来自识别滑动的代码。我究竟做错了什么?第一行是我认为泄漏的东西(使用仪器)。它被示为很多的错误负责主叫 这是在viewDidLoad中:使用手势识别器进行内存管理
UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightAction:)];
[(UISwipeGestureRecognizer *)swipeRight setNumberOfTouchesRequired:2];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
swipeRight.delegate = self;
[webView addGestureRecognizer:swipeRight];
UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeftAction:)];
[(UISwipeGestureRecognizer *)swipeLeft setNumberOfTouchesRequired:2];
swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
swipeLeft.delegate = self;
[webView addGestureRecognizer:swipeLeft];
// Do any additional setup after loading the view from its nib.
}
还有一个问题,是什么在这里可以导致一个僵尸?我应该自动回收?
AViewController *a = [[AViewController alloc]init];
[self.navigationController pushViewController:a animated:YES];
a.title [email protected]"A View";
[a release];
更新3:我跑的仪器寻找坏的分配,并与一些集约利用我这里得到僵尸: 错误消息:An Objective-C message was sent to a deallocated object (zombie) at address: 0xf583270.
在仪表这里是我所看到的。仪器突出显示这条线,并在其旁边有100%。
AViewController *a = [[AViewController alloc]init];
很好的解释!我仍然习惯于内存管理,这很有帮助! – Sum
顺便说一句,我添加了一个额外的代码的问题。那会是我想要使用autorelease的情况吗?如果我们快速地来回切换,这不是一个问题吗? – Sum
您添加的代码是正确的。添加一个autorelease并删除最终版本将导致相同的代码。这不会是我上面提到的问题,因为您不会在相同范围内更改对象。我上面描述的问题非常少见,每当我提到autorelease功能时,我都会提及它。 – ColdLogic