avplayer内存泄漏
我在应用程序启动时在我的项目中有一个Intro电影,我按照方法使用storyboard
,然后将我的MovieVC
作为初始视图,所以当应用程序启动时,会显示MovieVC
,然后当您按下或电影结束,它会呈现RootVC
。 当我testing它时,它在simulator
和device
工作,但是当我使用Leaks
进行testing时,发现了内存泄漏。
我不知道什么是错,我使用ARC,但我认为我的moviePlayer
器没有被释放,或者我的问题是在ViewControllers
。
这是我的MovieVC
代码:
- (void)viewDidLoad { self.view.backgroundColor = [UIColor whiteColor]; NSString *moviePath = [[NSBundle mainBundle] pathForResource:@"gameopening" ofType:@"m4v"]; self.moviePlayer = [AVPlayer playerWithURL:[NSURL fileURLWithPath:moviePath]]; [self.moviePlayer play]; // Create and configure AVPlayerLayer AVPlayerLayer *moviePlayerLayer = [AVPlayerLayer playerLayerWithPlayer:self.moviePlayer]; moviePlayerLayer.bounds = CGRectMake(0, 0, 1024, 768); moviePlayerLayer.position = CGPointMake(515,385); moviePlayerLayer.borderColor = [UIColor clearColor].CGColor; moviePlayerLayer.borderWidth = 3.0; moviePlayerLayer.shadowOffset = CGSizeMake(0, 3); moviePlayerLayer.shadowOpacity = 0.80; // Add perspective transform [self.view.layer addSublayer:moviePlayerLayer]; [super viewDidLoad]; [self performSelector:@selector(loadingView) withObject:nil afterDelay:33.0]; UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapGesture:)]; tapGesture.numberOfTapsRequired = 1; [self.view addGestureRecognizer:tapGesture]; [super viewDidLoad]; } - (void)handleTapGesture:(UITapGestureRecognizer *)sender { if (sender.state == UIGestureRecognizerStateEnded) { UIImageView *loadingView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]; loadingView.image = [UIImage imageNamed:@"Load.png"]; [self.view addSubview:loadingView]; [self performSelector:@selector(mainV) withObject:nil afterDelay:2.0]; } } -(void)loadingView{ UIImageView *loadingView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)]; loadingView.image = [UIImage imageNamed:@"Load.png"]; [self.view addSubview:loadingView]; [self performSelector:@selector(mainV) withObject:nil afterDelay:2.0]; } -(void)mainV { moviePlayer = nil; UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"mainViewController"]; vc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; [self presentViewController:vc animated:YES completion:NULL]; }
希望有人会帮助我做错了什么。 谢谢。
我会build议尝试使用设备运行仪器…因为以前有一些图书馆本身的问题。 如果在设备上泄漏消失,那么你很好去.. 🙂