I essentially have a menu, where bunch of buttons are displayed and every time one of them is clicked it leads to same view that is displayed differently depending on the item selected from the menu, there is also an mp4 playing. Every time I go into one of the items (different view) or return to the menu, my memory increases and never drops down, the views are presented modally if that makes any difference. I'm guessing the creep is caused by the mp4, how could I solve this problem?
import Foundation
import UIKit
import AVKit
import AVFoundation
class menu : UIViewController {
var info : AVPlayer?
var count = 0
@IBAction func instrumentas2(sender: UIButton) {
count = 2
}
@IBAction func instrumentas1(sender: UIButton) {
count = 1
}
@IBAction func instrumentas0(sender: UIButton) {
count = 0 }
override func viewWillAppear(animated: Bool) {
let videoURL: NSURL = NSBundle.mainBundle().URLForResource("info2", withExtension: "mp4")!
info = AVPlayer(URL: videoURL)
info?.actionAtItemEnd = .None
info?.muted = true
let playerLayer = AVPlayerLayer(player: info)
playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
playerLayer.zPosition = 1
playerLayer.frame = CGRect(x:20.0, y: 703.0, width: 36.0, height: 36.0)
view.layer.addSublayer(playerLayer)
info?.play()
NSNotificationCenter.defaultCenter().addObserver(self,
selector: "loopVideo",
name: AVPlayerItemDidPlayToEndTimeNotification,
object:nil)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
NSNotificationCenter.defaultCenter().removeObserver(self, name:AVPlayerItemDidPlayToEndTimeNotification, object: nil)
let du:display = segue.destinationViewController as! display
du.skaicius = count
}
func loopVideo() {
info?.seekToTime(kCMTimeZero)
info?.play()
}
}
I'm posting the whole thing because I honestly not sure what could be causing this.