AsyncSocket第三方开源库经常会在release环境下出现接收消息闪退
2016-03-08 13:43
387 查看
自从Xcode7出来以后,项目中使用的AsyncSocket第三方开源库经常会在release环境下出现接收消息闪退等现象,但是在debug环境下面则没有相关的问题,导致很难找到问题所在以及解决方法。在花费了很长时间查找资料以及相关问题搜索以后,发现有可能是因为在Xcode7在打包的时候,Xcode会自动精简代码块,导致问题某些代码在release环境下出现内存管理不到位而抛野指针,出现闪退现象。
在经过大量修改和测试以后,发现修改AsyncSocket开源库中的AsyncSocket.m的以下代码,闪退问题不在出现,修改前:
修改后的代码如下:
修改的核心是:为接收消息时的对象重新开辟一下内存,让其不会被提前释放而抛出野指针。
以上只是我个人的理解,有说错的或者不对的地方,希望大家能理解。
在经过大量修改和测试以后,发现修改AsyncSocket开源库中的AsyncSocket.m的以下代码,闪退问题不在出现,修改前:
/** * This is the callback we setup for CFReadStream. * This method does nothing but forward the call to it's Objective-C counterpart **/ static void MyCFReadStreamCallback (CFReadStreamRef stream, CFStreamEventType type, void *pInfo) { @autoreleasepool { AsyncSocket *theSocket = (__bridge AsyncSocket *)pInfo; [theSocket doCFReadStreamCallback:type forStream:stream]; } } /** * This is the callback we setup for CFWriteStream. * This method does nothing but forward the call to it's Objective-C counterpart **/ static void MyCFWriteStreamCallback (CFWriteStreamRef stream, CFStreamEventType type, void *pInfo) { @autoreleasepool { AsyncSocket *theSocket = (__bridge AsyncSocket *)pInfo; [theSocket doCFWriteStreamCallback:type forStream:stream]; } }
修改后的代码如下:
static void MyCFReadStreamCallback (CFReadStreamRef stream, CFStreamEventType type, void *pInfo) { @autoreleasepool { AsyncSocket *theSocket =[[AsyncSocket alloc]init]; theSocket = (__bridge AsyncSocket *)pInfo; [theSocket doCFReadStreamCallback:type forStream:stream]; } } static void MyCFWriteStreamCallback (CFWriteStreamRef stream, CFStreamEventType type, void *pInfo) { @autoreleasepool { AsyncSocket *theSocket =[[AsyncSocket alloc]init]; theSocket = (__bridge AsyncSocket *)pInfo; [theSocket doCFWriteStreamCallback:type forStream:stream]; } }
修改的核心是:为接收消息时的对象重新开辟一下内存,让其不会被提前释放而抛出野指针。
以上只是我个人的理解,有说错的或者不对的地方,希望大家能理解。
相关文章推荐
- 安卓MVC vs MVP 框架
- 机房收费系统---工程过程的图
- jQuery实现的分页功能,包括ajax请求,后台数据,有完整demo
- iOS app的webview注入JS遇到的坑
- MeanShift 目标跟踪算法
- 返回json数据null判断问题
- Java获取客户端(浏览器)的MAC地址
- 华为OJ 计算字符串的距离
- 编程之美3.7 队列中最大值问题
- 使用 php 内部web服务器
- ionic dev env
- HDOJ 1848 Fibonacci again and again
- django --fields.E304 错误解决方案
- 苹果改版之后,关于隐私协议加入的问题解决方式
- socket listen backlog
- you don't know js读书笔记
- PAT basic 1041
- 怎样羽化和锐化Zbrush遮罩边界
- foreach 相关
- iOS uiwebview 大小跟随内容自适应