Memory Leakage During Full Screen Movie Playback in AVPlayerViewController

Asked 2 years ago, Updated 2 years ago, 101 views

I use AVPlayerViewController to build a screen to play videos.
There is no problem for normal playback, but
Move the video to full-screen playback from the full-screen mode switch button on the far right of the player's controller
Restoring to normal size results in a large amount of memory leaks.

Reproduce the following code in your environment (Xcode 8.0, Swift 2.3, iPhone 6s):

import UIKit
import AVKit
import AVFoundation

classMoviePlayViewController:UIViewController {

  varplayerViewController —AVPlayerViewController!

  override func viewDidLoad(){
    super.viewDidLoad()

    self.playerViewController=AVPlayerViewController()
    self.playerViewController.view.frame = CGRectMake(0,64,320,240)

    let path = NSBundle.mainBundle().pathForResource("hoge", ofType:"mp4")
    let url = NSURL (fileURLWithPath:path!)

    self.playerViewController.player=AVPlayer (URL: url)
    self.view.addSubview(self.playerViewController.view)
    self.addChildViewController (self.playerViewController)
    self.playerViewController.didMoveToParentViewController(self)
  }

  override funcdidReceiveMemoryWarning(){
    super.didReceiveMemoryWarning()
  }
}

The contents of the leak are as follows.
Enter a description of the image here

AVKit leak details.
Enter a description of the image here


because we are unable to determine if there is a problem with the implementation method or AVPlayerViewController side. If anyone knows, please let me know the cause and solution.
Thank you for your cooperation.

swift ios memory-leaks

2022-09-29 20:29

2 Answers

I also reproduced it using the actual machine.I think it's an Apple SDK bug.We recommend reporting from https://bugreporter.apple.com.

Also, var playerViewController: AVPlayerViewController doesn't have to be a strong reference, so I tried to use the optional peak, but the memory leak didn't disappear

In order to avoid memory leaks at this time, I think you need to scratch players by using AVPlayerLayer instead of using AVPlayerViewController.


2022-09-29 20:29

The Apple Bug Reporter reported this matter, but
I received a reply today saying that it will be closed due to duplication.

The duplicate destination was Duplicate of 29519477 (Closed), so
I think it's probably solved.Will it be in the next release?

That was information sharing.


2022-09-29 20:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.