[英]AVPlayerViewController memory leak/retain cycle?
我的應用程序不斷出現問題,其中 AVPlayerViewController 在被解雇后不會從內存中清除,它只會在每次演示后積累更多。
這是在 iOS 12 上,在一個空項目中嘗試以下操作,例如我在viewDidAppear
執行此操作,以使其在關閉后幾秒鍾自動彈出。 如果您轉到 Xcode 底部的“調試內存圖”工具,您會注意到在一堆解雇之后,AVPlayerViewController 保留在內存中,並且有很多實例。
但關鍵是讓視頻播放到最后,控件會彈出。
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(6)) { [weak self] in
let assetURL = URL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!
let player = AVPlayer(url: assetURL)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self?.navigationController?.present(playerViewController, animated: true) {
playerViewController.player!.play()
}
}
}
嘗試這個
self?.navigationController?.present(playerViewController, animated: true) { [weak playerViewController]
playerViewController?.player!.play()
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.