最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

[暂时解决]iOS swift程序崩溃:_dispatch_xref_dispose object_dispose

iOS crifan 3265浏览 0评论

之前程序在退出登录时是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

objective c blocks – iOS5 stable app crashes in iOS 6 with dealloc:objc_storeStrong:objc_release:_dispatch_xref_dispose – Stack Overflow

Crash in ATLConversationViewController · Issue #873 · layerhq/Atlas-iOS

ios crash _dispatch_xref_dispose

调度源释放|苹果开发者论坛

ios crash object_dispose

iphone – Unable to understand the real cause behind this symbolicated crash report affecting only iOS 4.3.x users – Stack Overflow

Crash in [UIAXDelegateClearer dealloc] | Apple Developer Forums

Dispatch Sources

试了各种:

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

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
90 queries in 0.216 seconds, using 22.13MB memory