完整报错如下:
-[CFString isEqualToString:]message sent to deallocated instance
代码如下:
dispatch_async(self.queue, ^{
if ([RAUtility isUploadHost:request]) {
return;
}
.............//后面还有一部分代码
});
+ (BOOL)isUploadHost:(NSURLRequest *)request {
if (!request) {
return NO;
}
// 去掉尾部'/'再进行比较
NSString *requestURLString = request.URL.absoluteString;
NSString *testAddress = [APM getTestUploadAddress];
BOOL isUploadHost = [requestURLString isEqualToString:testAddress] ||
[requestURLString isEqualToString:APM_UPLOADADDRESS];
return isUploadHost;
}
崩溃出现在
BOOL isUploadHost = [requestURLString isEqualToString:testAddress] ||
[requestURLString isEqualToString:RichAPM_UPLOADADDRESS];"
开启僵尸检测xode 日志如下:
*** -[CFString isEqualToString:]: message sent to deallocated instance 0x101393e00
po requestURLString
2017-02-20 15:27:15.448664 Browser[4170:294768] *** -[CFString respondsToSelector:]: message sent to deallocated instance 0x101393e00
class name = _NSZombie_CFString
po request.URL.absoluteString
https://m.baidu.com/tc?tcreq4log=1&ssid=0&from=844b&pu=sz%401320_2001%2Cta%40iphone_1_10.2_3_602&qid=9501293810319954737&ct=10&cst=4&ref=index_iphone&lid=9501293810319954737&w=0_0_&sid=114455_102568_104496_100183_102478_106371_107324_109550_114000_110313_107918_112107_107315_112135_114125_114077_114512_114329_114534_114202_114313_112093_114276_114718_110085&rids=13115399611138481457&pos=13&clk_from=mid_news&stype=&extra=%7B%22category%22:0,%22cb_lr_expid%22:0,%22cb_lr_score%22:0,%22cb_manual_score%22:0,%22channel_id%22:0,%22click%22:9328,%22coverquality%22:0,%22cs%22:%22%22,%22flag%22:1,%22genre%22:0,%22index_expid%22:0,%22label%22:%5B%5D,%22live_type%22:0,%22mark%22:6,%22mark_rec%22:6,%22mthid%22:%22-1%22,%22rec_src%22:%5B9%5D,%22score%22:42118.4,%22show%22:96974,%22source%22:0,%22srccat%22:0,%22steplength%22:-1,%22top%22:0,%22type%22:0%7D&logExtra=%7B%22st%22:%22video%22,%22source%22:%22small_video%22,%22extra%22:%22%7B%5C%22category%5C%22:0,%5C%22cb_lr_expid%5C%22:0,%5C%22cb_lr_score%5C%22:0,%5C%22cb_manual_score%5C%22:0,%5C%22channel_id%5C%22:0,%5C%22click%5C%22:9328,%5C%22coverquality%5C%22:0,%5C%22cs%5C%22:%5C%22%5C%22,%5C%22flag%5C%22:1,%5C%22genre%5C%22:0,%5C%22index_expid%5C%22:0,%5C%22label%5C%22:%5B%5D,%5C%22live_type%5C%22:0,%5C%22mark%5C%22:6,%5C%22mark_rec%5C%22:6,%5C%22mthid%5C%22:%5C%22-1%5C%22,%5C%22rec_src%5C%22:%5B9%5D,%5C%22score%5C%22:42118.4,%5C%22show%5C%22:96974,%5C%22source%5C%22:0,%5C%22srccat%5C%22:0,%5C%22steplength%5C%22:-1,%5C%22top%5C%22:0,%5C%22type%5C%22:0%7D%22,%22stype%22:null,%22rid%22:%2213115399611138481457%22,%22pos%22:13,%22picNum%22:1,%22title%22:%22%5Cu53f0%5Cu6e7e%5Cu6700%5Cu65b0%5Cu6027%5Cu6559%5Cu80b2%5Cu77ed%5Cu7247%20%5Cu7edd%5Cu5bf9%5Cu9707%5Cu64bc%5Cu5fc3%5Cu7075%22%7D&r=1487575566391
堆栈信息
(lldb) bt
* thread #12: tid = 0x47f70, 0x000000018a1951c4 CoreFoundation`___forwarding___ + 744, queue = 'com.rich.RichNetworkRecorder', stop reason = EXC_BREAKPOINT (code=1, subcode=0x18a1951c4)
frame #0: 0x000000018a1951c4 CoreFoundation`___forwarding___ + 744
* frame #1: 0x000000018a08e80c CoreFoundation`_CF_forwarding_prep_0 + 92
frame #2: 0x000000010012f580 Browser`+[RAUtility isUploadHost:](self=RAUtility, _cmd="isUploadHost:", request=0x0000000170209840) + 220 at RAUtility.m:24
frame #3: 0x000000010011a36c Browser`__105-[RANetworkRecorder recordRequestWillBeSentWithRequestID:request:redirectResponse:class:selector:thread:]_block_invoke((null)=<unavailable>) + 64 at RANetworkRecorder.m:73
frame #4: 0x000000010035d258 libdispatch.dylib`_dispatch_call_block_and_release + 24
frame #5: 0x000000010035d218 libdispatch.dylib`_dispatch_client_callout + 16
frame #6: 0x000000010036aaec libdispatch.dylib`_dispatch_queue_serial_drain + 1136
frame #7: 0x0000000100360ce0 libdispatch.dylib`_dispatch_queue_invoke + 672
frame #8: 0x000000010036ce2c libdispatch.dylib`_dispatch_root_queue_drain + 584
frame #9: 0x000000010036cb78 libdispatch.dylib`_dispatch_worker_thread3 + 140
frame #10: 0x00000001892232a0 libsystem_pthread.dylib`_pthread_wqthread + 1288
frame #11: 0x0000000189222d8c libsystem_pthread.dylib`start_wqthread + 4
想问如下问题:
1.po 为何可以打印request.URL.absoluteString的值而不能打印requestURLString,requestURLString不是指向request.URL.absoluteString?
2.我查了下,request 对url 是copy,URL 对absoluteString又是copy,是不是可以说明是request被释放了?
3.但是po仍然可以打印出request,
(lldb) po request
<NSURLRequest: 0x170209840> { URL: https://m.baidu.com/tc?
4.你觉得可能哪里出了问题,该怎么修复?
PHPz2017-04-18 09:56:08
The existence of request does not guarantee the existence of absoluteString
PHP中文网2017-04-18 09:56:08
NSString *requestURLString = request.URL.absoluteString;
This sentence cannot be used in this way. request.URL.absoluteString is a reference type value. requestURLString needs to be initialized, such as using stringWithFormat.