可达性课程崩溃程序-不确定原因 [英] Reachability Classes crashing program - not sure why

查看:100
本文介绍了可达性课程崩溃程序-不确定原因的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于需要在我的应用程序中联网的对象,我有一个可识别互联网的"基类.所有需要了解Internet的对象都继承自它.可以想象,我分配和取消分配了许多这些对象.

I have an 'internet aware' base class for objects which require networking in my app. All the objects which need to be internet aware inherit from it. As you can imagine I allocate and deallocate a lot of these objects.

具有Internet意识的基类具有以下代码,可与用于检查Internet状态的Reachability类进行交互.

The internet aware base class has the following code to interact with the Reachability classes used to check for internet status.

#import "Reachability.h"

- (id) init {
    ...
    self.internetReachable = [Reachability reachabilityForInternetConnection];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(checkNetworkStatus) name:kReachabilityChangedNotification object:nil];
    [self.internetReachable startNotifier];
    ...
  }
- (void)  dealloc
 {
    [self.internetReachable stopNotifier];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
 }

一旦我的应用程序的互联网状态发生变化,该应用程序就会崩溃并显示以下错误:

As soon as there is a change in internet status in my app, the app crashes with the following error:

***-[Reachability isKindOfClass:]:消息发送到已释放 实例0x1e249a30

*** -[Reachability isKindOfClass:]: message sent to deallocated instance 0x1e249a30

我已经打开了僵尸,并在Reachability.m中将问题跟踪到了以下代码行.

Ive turned on zombies and tracked the problem down to the following line of code within Reachability.m

NSCAssert([(NSObject*) info isKindOfClass: [Reachability class]], @"info was wrong class in ReachabilityCallback");

不幸的是,除了停止侦听NSNotifcations和停止通知程序外,我不确定我的对象还能做些什么来避免此错误.

Unfortunately, beyond stopping listening for NSNotifcations and stopping the notifier, im not sure what else my objects can do to avoid this error.

任何帮助或建议都很好.

Any help or suggestions would be great.

谢谢

Vb

好吧,所以按照下面答案的建议,我在带有分配的工具中运行了它 这就是保留计数的历史记录.

OK so following the advice of the answer below I ran it in instruments with allocations and this was the retain count history.

正如我所怀疑的,它是我已经释放的一个对象,是由基金会(即NSNotifcationCenter)而不是我自己调用的.

It is as I suspected, its an object that I have deallocated being called by Foundation (ie. NSNotifcationCenter) and not myself.

我的Internet对象有一个很强的指向Reachability对象的指针.释放它们时,可达性对象也将被释放.僵尸是可达性对象. 在我的Internet对象的解除分配中,我调用了removeObserver,但是Foundation仍在调用释放对象.我不明白为什么...

My internet objects have a strong pointer to a Reachability object. When they are deallocated, so is the Reachability object. The zombie is the Reachability object. In the dealloc of my internet object I have called removeObserver, but foundation is still calling the deallocated object. I can't understand why...

推荐答案

NSCAssert行是您首次访问已释放对象的位置,但是如果您想了解有关该对象生命周期的更多信息,则应该使用Instruments.使用Xcode的配置文件工具通过分配"(但不要泄漏!)工具在模拟器中运行程序.在分配工具的启动配置中,启用启用NSZombie检测"和"记录引用计数".当您点击NSCAssert行时,Instruments应该检测到尝试向僵尸信息对象发送消息并记下它的尝试.如果您查看僵尸信息对象的详细信息,仪器将向您显示其引用计数的历史记录,您应该能够看到它何时被释放.

The NSCAssert line is where you first access the deallocated object, but if you want to know more about the object's life cycle you should use Instruments. Use Xcode's Profile tool to run your program in the simulator with the Allocations (but not leaks!) tool. In the allocations tool's launch configuration turn on Enable NSZombie Detection and Record Reference Counts. When you hit the NSCAssert line Instruments should detect the attempt to message the zombie info object and make a note of it. If you look at the detailed information for the zombie info object Instruments will show you its history of reference counts and you should be able to see when it was deallocated.

这篇关于可达性课程崩溃程序-不确定原因的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆