ASINetworkQueue:尝试在已释放的委托上执行选择器

发布于 2024-10-18 21:06:06 字数 383 浏览 3 评论 0原文

我正在使用来自的示例代码 https://gist.github.com/150447

当视图控制器卸载时,我将网络队列设置为nil,并调用重置方法。

[[self networkQueue1]重置];
[自我设置NetworkQueue1:nil];

但一旦我返回到以前的视图控制器,我仍然会遇到异常。

* -[myViewController PerformSelector:withObject:]:消息发送到已释放的实例 0xc1d1bb0

请提出问题所在。

谢谢,

I am using the sample code from
https://gist.github.com/150447

when the viewcontroller unloads, im setting the networkqueue to nil, and also calling the reset method.

[[self networkQueue1] reset];
[self setNetworkQueue1:nil];

but still i get exception as soon as i go back to previous view controller.

* -[myViewController performSelector:withObject:]: message sent to deallocated instance 0xc1d1bb0

Please suggest whats going wrong.

Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

狂之美人 2024-10-25 21:06:06

您需要在 dealloc() 方法或更早的方法中将所有委托清零。根据您要设置的委托等,应该这样做:

for (ASIHTTPRequest *req in [queue operations])
{
    [req cancel];
    [req setDelegate:nil];
}
[queue setDelegate:nil];

基本上,您需要确保委托在销毁之前删除任何当前请求 - 这将确保释放的委托永远不会被调用。

You need to nil any delegates in the dealloc() method or earlier. Depending on exactly which delegates etc you're setting, something like this should do it:

for (ASIHTTPRequest *req in [queue operations])
{
    [req cancel];
    [req setDelegate:nil];
}
[queue setDelegate:nil];

Basically, you need to make sure the delegate is removed any current request before the delegate is destroyed - this will make sure that a deallocated delegate will never get called.

简单爱 2024-10-25 21:06:06

请参阅这篇文章

基本上,一个对象仍然具有对视图控制器的引用(可能因此它可以对其进行回调),并且当您返回到以前的 VC,当前的 VC 正在被释放(正如它应该的那样)。您需要找到该对象,并将其对您的 VC 的引用清零(可能称为“委托”或“回调”)。
希望有帮助。

Please see this post NSURLConnection gives EXC BAD ACCESS when tap on other tab while data loading

Basically, an object still has a reference to your view controller (probably so it can do a callback to it), and when you go back to the previous VC, the current VC is being deallocated (as it should.) You need to find that object, and nill out it's reference to your VC (probably called "delegate" or "callback").
Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文