postNotificationName:XXXXXX carsh
[[NSNotificationCenter defaultCenter] postNotificationName:XXXXXX object:self];
經(jīng)過(guò)推理得出結(jié)論:
因?yàn)橥ㄖ侨之惒降?self有可能被釋放掉了,或許通知沒用對(duì)數(shù)據(jù)加鎖or something
網(wǎng)上搜索也得出了相似的答案
- I've seen no documentation that promises that. You can try to explore it by making dealloc very slow (using sleep() for instance) and adding printf() logging. (Never do threading analysis with NSLog.) But I doubt you could rely on the results. Even if ARC promised it, you can't know whether NSNotificationCenter uses ARC internally. The only real promises are what you get from the docs. – Rob Napier Dec 6 '12 at 18:05
這樣使用為什么會(huì)有崩潰問(wèn)題呢?
因?yàn)闀?huì)隨機(jī)遇見僵尸內(nèi)存問(wèn)題
Are there any workaround for randomly crash?
Enable zombies - this will cause the exception to breakpoint on the offending line. From there it will be a lot easier to figure out than the general EXC_BAD_ACCESS crash.
那如何解決呢?
1 .翻看sdwebimage源碼看到了如下代碼(本人未驗(yàn)證)(以測(cè)試,沒有用)
__block typeof(self) strongSelf = self;
[[NSNotificationCenter defaultCenter] postNotificationName:XXXXXX object:strongSelf ];
2.轉(zhuǎn)地址(本人未驗(yàn)證)
地址獲取與此類似
__block typeof(self) strongSelf = self;
NSInteger nSelf = (long)(__bridge void *)self;
NSNumber *number = @(nSelf);
[[NSNotificationCenter defaultCenter] postNotificationName:XXXXXX object:number];
//接受通知對(duì)象轉(zhuǎn)換成self
NSObject *obj = (__bridge NSObject*) object.integerValue;