AVPlayerViewController内存泄漏/保留周期?

问题描述 投票:0回答:1

我的应用程序一直存在问题,即AVPlayerViewController在被解雇后不会从内存中清除,它只会在每次演示后积累更多。

[这是在iOS 12上,在一个空项目中尝试以下操作,例如,我在viewDidAppear中执行了此操作,以使其自动消失后弹出几秒钟。一堆解雇后,您会注意到,如果转到Xcode底部的“ Debug Memory Graph”工具,则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()
        }
    }
}
ios cocoa-touch avfoundation avplayer avplayerviewcontroller
1个回答
0
投票

尝试一下

self?.navigationController?.present(playerViewController, animated: true) { [weak playerViewController]
        playerViewController?.player!.play()
    }
© www.soinside.com 2019 - 2024. All rights reserved.