Memory dealloc general xcode brief
I'm pretty new to rapid iOS development and I'm having a problem understanding memory management.
Im app is working on a chain of table views ending with an AVPlayerView controller playing videos from streaming URLs.
When running the application in the simulator and observing the memory bar, I see that going back from one table view to the previous one can reduce memory. However, when entering the AVPlayerView controller, the memory is increased and then returning to the previous View table does not decrease the memory.
I'm using the following code on my PlayerView controller (viewDidLoad):
var player : AVPlayer? = nil
let playerController = AVPlayerViewController()
var playerItem = AVPlayerItem(URL: mediaUrl)
self.player = AVPlayer(playerItem: playerItem)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "playerDidFinishPlaying:", name: AVPlayerItemDidPlayToEndTimeNotification, object: playerItem)
self.playerController.showsPlaybackControls = false
self.playerController.player = self.player
self.addChildViewController(self.playerController)
self.view.addSubview(self.playerController.view)
self.playerController.view.frame = self.view.frame
self.view.addSubview(self.scrub)
self.player!.play()
and to exit the controller and go back to the previous controller:
self.player!.pause()
self.navigationController?.navigationBarHidden = false
navigationController?.popViewControllerAnimated(true)
Inside the player, I use a button to navigate from one video to another using:
self.player!.replaceCurrentItemWithPlayerItem(playerItem)
using this video change, but not increasing the memory. In fact, it decreases significantly and then returns to normal, so I have to assume that the memory is controller related and I must have missed something.
I could explain how it works, it would be very helpful. Maybe it's completely normal and I'm worried about nothing, but if I wasn't happy to fix it. PS: I have to say that the application is working fine and I don't have any crash or anything else.
thank
EDIT / UPDATE
Before entering the PlayerView controller, I usually use about 25 million of allocated memory. After playing the video I'm about 125Mo.
I was able to reduce this memory to 75 by setting the AVPlayer to zero before rejecting the controller. I also remove the PlayerView layer from it with the parent controller, but this does not affect memory.
self.player!.pause()
self.playerController.player = nil
self.playerController.removeFromParentViewController()
self.navigationController?.navigationBarHidden = false
navigationController?.popViewControllerAnimated(true)
source to share
No one has answered this question yet
Check out similar questions: