之前程序在退出登录时是OK的
但是自从添加了一个类MessageManager
结果退出时就崩溃了
猜测是和之前添加的dispatch_source_t的定时器又关系
所以又去添加了deinit去释放dispatch_source_t:
deinit {
gLog.debug("")
dispatch_source_cancel(self.markHasReadTimer)
}
但是还是会崩溃:
把deinit去掉,结果:
ios crash _dispatch_xref_dispose object_dispose
Crash in ATLConversationViewController · Issue #873 · layerhq/Atlas-iOS
ios crash _dispatch_xref_dispose
ios crash object_dispose
Crash in [UIAXDelegateClearer dealloc] | Apple Developer Forums
试了各种:
1.
deinit {
gLog.debug("")
// dispatch_source_cancel(self.markHasReadTimer)
// dispatch_suspend(self.markHasReadTimer)
// dispatch_release(self.markHasReadTimer)
}
2.
func doQuitHandler(alerAction:UIAlertAction){
// SingletonMessageManager().stopMarkHasRead()
resetGlobalValues()
showLoginView()
}
// func stopMarkHasRead() {
//// dispatch_source_cancel(self.markHasReadTimer) //will case startMarkHasRead->dispatch_resume crash
//// dispatch_suspend(self.markHasReadTimer)
// dispatch_source_cancel(MessageManager.markHasReadTimer)
// }
都不行。
后来实在找不到,如何能够取消掉dispatch_source_t的markHasReadTimer
然后弄成了个:类的static变量:
class MessageManager: NSObject {
static var markHasReadTimer:dispatch_source_t = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0))
override init() {
self.markHasReadDict = [String:Int]()
// let backgroundQueue = dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)
// self.markHasReadTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, backgroundQueue)
super.init()
}
deinit {
gLog.debug("")
// dispatch_source_cancel(self.markHasReadTimer)
// dispatch_suspend(self.markHasReadTimer)
// dispatch_release(self.markHasReadTimer)
}
func startMarkHasRead(curMsgTVC:MessageTableViewController) {
gLog.debug("curMsgTVC=\(curMsgTVC), name=\(curMsgTVC.contactItem.name), id=\(curMsgTVC.contactItem.id)")
let startTime:dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, 0)
let intervalInSec:UInt64 = MarkHasReadIntervalInSec * NSEC_PER_SEC
let leeway:UInt64 = 0 * NSEC_PER_SEC
dispatch_source_set_timer(MessageManager.markHasReadTimer, startTime, intervalInSec, leeway)
dispatch_source_set_event_handler(MessageManager.markHasReadTimer, {
self.tryMarkHasRead(curMsgTVC)
})
dispatch_resume(MessageManager.markHasReadTimer)
}
func endMarkHasRead(curMsgTVC:MessageTableViewController) {
gLog.debug("curMsgTVC=\(curMsgTVC), name=\(curMsgTVC.contactItem.name), id=\(curMsgTVC.contactItem.id)")
// dispatch_source_cancel(self.markHasReadTimer) //will case startMarkHasRead->dispatch_resume crash
dispatch_suspend(MessageManager.markHasReadTimer)
}
终于使得之后的resetMessageManager:
func resetMessageManager() -> MessageManager {
gMessageManager = MessageManager()
return gMessageManager
}
可以正常执行,不会崩溃了。
但是根本的原因,暂时没搞懂,有空再说。
转载请注明:在路上 » [暂时解决]iOS swift程序崩溃:_dispatch_xref_dispose object_dispose