简体   繁体   中英

CADisplayLink because of remove(from:forMode:) not deallocating view controller

I am facing one strange issue.

So I have created instance and allocated like below

var displayLink:CADisplayLink?

private func setupDisplayLink () {

    self.displayLink = CADisplayLink(target: self, selector: #selector(displayLinkDidFire(link:)))
    self.displayLink?.preferredFramesPerSecond = 30
    self.displayLink?.add(to: .main, forMode: .common)
}

Now to remove display link I have from this Answer

self.displayLink?.remove(from: .main, forMode: .common) // comment this line and view controller correctly deallocated 
self.displayLink?.invalidate()

because of line self.displayLink?.remove(from: .main, forMode: .common) my deinit method not called of view controller

In memory graph I am not able to identify the real problem. I was lucky that I have tried to comment that line and it works

在此输入图像描述

Why that so ?

Stop displayLink like this:

displayLink?.invalidate()
displayLink = nil

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM