AsyncSocket EXC_BAD_ACCESS unrecognized selector sent to instance:0x6000001908e0
来源:互联网 发布:c语言间接寻址 编辑:程序博客网 时间:2024/06/14 09:33
一、问题
IOS使用AsyncSocket 会在下面代码处 报 EXC_BAD_ACCESS unrecognized selector sent to instance:0x6000001908e0
- (void)closeWithError:(NSError *)err
{
theFlags |=kClosingWithError;
if (theFlags &kDidStartDelegate)
{
// Try to salvage what data we can.
[selfrecoverUnreadData];
// Let the delegate know, so it can try to recover if it likes.
if ([theDelegaterespondsToSelector:@selector(onSocket:willDisconnectWithError:)])
{
[theDelegateonSocket:selfwillDisconnectWithError:err];
}
}
[selfclose];
}
二、debug
1. 使用快捷键 command+I 打开 Xcode调试工具Instruments。
2. 双击打开下图Zombies 。
三、解决办法
从debug 发现 封装的 MySocket 是僵尸对象。 故改为单例模式:
MySocket.h
@interface MySocket : NSObject
{
AsyncSocket *socket;
}
@property (nonatomic,strong)AsyncSocket *socket;
+ (MySocket *)sharedSocket;
-(void)connectHost:(NSString *)host;
===========================================================================================
MySocket.m
@implementation MySocket
@synthesize socket=_socket;
+(MySocket *)sharedSocket
{
staticMySocket *sharedInstace =nil;
staticdispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstace = [[selfalloc]init];
});
return sharedInstace;
}
-(void)connectHost:(NSString *)host{
if (!self.socket) {
self.socket = [[AsyncSocketalloc]initWithDelegate:self];
NSError *err =nil;
if(![self.socketconnectToHost:hostonPort:SOCKET_PORTerror:&err])
{
NSLog(@"Connect Error: %@", err);
}else{
NSLog(@"Connect success!");
}
}
}
- AsyncSocket EXC_BAD_ACCESS unrecognized selector sent to instance:0x6000001908e0
- unrecognized selector sent to instance 0x81de740
- unrecognized selector sent to instance 0x266070
- unrecognized selector sent to instance 0x266070
- unrecognized selector sent to instance 0x10b34e810
- unrecognized selector sent to instance 0x266070
- unrecognized selector sent to instance
- unrecognized selector sent to instance
- unrecognized selector sent to instance
- unrecognized selector sent to instance
- unrecognized selector sent to instance
- unrecognized selector sent to instance
- unrecognized selector sent to instance
- unrecognized selector sent to instance
- unrecognized selector sent to instance
- unrecognized selector sent to instance
- unrecognized selector sent to instance
- [NSCFType XXX]: unrecognized selector sent to instance 0x4d80b00'
- LeetCode
- hibernate的懒加载
- 自定义属性
- java学习中的小问题(Integer、String)
- 【庖丁解牛系列】 项目时间管理之前导图/单代号网络图
- AsyncSocket EXC_BAD_ACCESS unrecognized selector sent to instance:0x6000001908e0
- Excel无法打开文件xxx.xlsx,因为文件格式或文件扩展名无效。请确定文件未损坏,并且文件扩展名与文件的格式匹配
- 直击CVPR2017:商汤科技打造技术盛宴23篇论文刮起中国风 By 机器之心2017年7月25日 10:14 近日,CVPR2017 在夏威夷如火如荼地进行,作为全球计算机视觉顶级会议,CVPR
- Linux 通配符用法简介
- [USACO2.3]控制公司 Controlling Companies
- 高性能MySQL 索引章节温习笔记
- 从拖延到高效,我推荐这 7 本书(附带PDF地址)
- [zabbix/自动发现规则]
- LVS-NAT模式的部署配置