avplayer内存泄漏 [英] avplayer memory leak

查看:57
本文介绍了avplayer内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

应用程序启动时,我的项目中有一部Intro电影,顺便说一句,我正在使用 storyboard ,然后将 MovieVC 用作初始视图",因此当应用程序启动时,会显示 MovieVC ,然后在您按下或电影结束时,它将显示 RootVC .当我对其进行测试时,它可以在 simulator device 中工作,但是当我使用 Leaks 使用 instruments 对其进行测试时,内存发现泄漏.

I have an Intro movie in my project when the app starts, I'm using storyboard by the way, then I make my MovieVC as the Initial View, so when the app starts, the MovieVC is shown then when you pressed or the movie ends, it will present the RootVC. Its working in simulator and device when I tested it, but when I test it with instruments using Leaks, memory leaks were discovered.

我不知道出了什么问题,我正在使用ARC,但是我认为我的 moviePlayer 没有发布,或者我的问题出在 ViewControllers 中.

I don't know what's wrong, Im using ARC, but I think my moviePlayer isn't being release or my the problem is in the 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];   
}

希望有人会对我做错的事情有所帮助.谢谢.

Hope someone will help on what I am doing wrong. Thankyou.

推荐答案

我建议尝试使用device ...来运行该仪器,因为之前该库本身存在一些问题.如果在设备上泄漏消失了,那么您就可以走了..:)

I will suggest try running the instrument using device... as previous there was some problem with the library itself. If on device the leak disappear then you are good to go.. :)

这篇关于avplayer内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆