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/

相关文章:

iphone - iPhone 上的 UIModalPresentationFormSheet

ios - 如何打印NSSet的内容?

ios - 旋转呈现 View 并锁定呈现 View Controller 的方向

ios - 如何清除mkmapview的缓存

iphone - 使用 UIScrollView 生成问题

iPhone 相机 - 使用 imac 网络摄像头代替?

iphone - 数字格式化程序:我需要01而不是1

ios - UITableViewController 仅在离开并返回 UITableViewController 后才在页面顶部留下空间

iphone - UIView 过渡动画不显示 subview

iOS7 Sprite Kit 如何禁用对 Sprite 的触摸以使其成为 "tap through"?