iphone - avplayer内存泄漏

标签 iphone objective-c ios xcode

当应用程序启动时,我的项目中有一个介绍影片,顺便说一句,我正在使用 storyboard,然后我将 MovieVC 作为初始 View ,所以当应用程序启动时,会显示 MovieVC,然后当您按下或电影结束时,它将显示 RootVC。当我测试它时,它在模拟器和设备中工作,但是当我使用Leaks使用instruments测试它时,内存发现泄漏。

我不知道出了什么问题,我正在使用 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];   
}

希望有人能帮助我解决我做错的事情。谢谢。

最佳答案

我建议尝试使用设备运行仪器...如前所述,库本身存在一些问题。 如果设备上的泄漏消失,那么您就可以开始了..:)

关于iphone - avplayer内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12595594/

相关文章:

javascript - Phonegap 文本区域滚动

objective-c - NSFileManager 找不到/var/mobile/的路径

ios - 确定何时将 subview 添加到 tableView

iphone - 多次按下时声音重叠

iPhone:学习资源 'instruments' ?

objective-c - 我正在制作一个应用程序,并放置了一个 iAd,但我希望它在不可用时隐藏

ios - 捕获当前时间但将分钟重置为零而不处理时区

objective-c - 将 NSString 分离到 NSArray 中,但允许引号对单词进行分组

android - Cordova android地理定位超时

ios - 用户滚动时如何停止视频