YTPlayerView memory issue

484 Views Asked by At

I am using YTPlayerView for showing YouTube videos in my application. I instantiate the YTPlayerView in an IBAction function with a variable that is local to that function. Something along the lines of:

IBAction func presentPlayer(sender: UIButton){
    let playerViewController = UIStoryboard(name: "Player", bundle: nil).instantiateViewControllerWithIdentifier("YoutubePlayer") as! PlayerViewController
    self.presentViewController(playerViewController, animated: true, completion: nil)
}

The PlayerViewController has a class variable of type YTPlayerView. There is a done button which dismisses the PlayerViewController. My problem is the memory level does not come down to the same level as it was before I presented the player. Instruments shows some memory leaks relating to UIWebView but I am unable to reach the source. Any help would be appreciated. Here's what I have done so far when I dismiss the PlayerViewController on click of the done button:

IBAction func donePressed(sender: UIButton){
    self.customYTPlayer.stopVideo()//customYTPlayer is my YTPlayerView
    self.customYTPlayer.removeWebView()
    self.removeYTPlayerSubviews(self.customYTPlayer)
    self.customYTPlayer=nil
}

removeYTPlayerSubviews function I have written as:

func removeYTPlayerSubviews(ytplayerView:UIView){
    if ytplayerView.subviews.count > 0{
        for subview in ytplayerView.subviews{
            subview.removeFromSuperview()
            self.removeYTPlayerSubviews(subview)
        }
    }
}
1

There are 1 best solutions below

0
On

Got it!!..while testing in instruments, it showed this message while delving into the memory leaks

[UIWebSelectionAssistant addNonEditableForceTextSelectionGestureRecognizersToView:]

searching for this online brought me to https://forums.developer.apple.com/thread/25526

Here is says that this is an UIWebView issue in iOS 9 and does not occur in iOS 8. On running my app in iOS 8 simulator I got no leaks. So I guess its an Apple issue after all. Hope they sort it out soon...