Object release thread management OC-

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/shengpeng3344/article/details/100020574

Under ARC mode, the object will release the reference counter is 0, when we want to manage their release thread, the child thread in its reference count is set to 0

class MyMutableArray : NSMutableArray {
    deinit {
        print("deinit \(Thread.current)")
    }
}

class ViewController: UIViewController {
    var marray : MyMutableArray?

    override func viewDidLoad() {
        super.viewDidLoad()
        self.marray = MyMutableArray.init();
        let tmp = self.marray;
        self.marray = MyMutableArray.init()
        //去掉下面代码则在主线程释放
        DispatchQueue.global().async {
            tmp?.classForCoder
        }
    }

Console output is:

deinit <NSThread: 0x6000039ecac0>{number = 3, name = (null)}

That which thread counter to zero, in which thread release.

Guess you like

Origin blog.csdn.net/shengpeng3344/article/details/100020574