avplayer内存泄漏

时间:2012-09-26 06:14:40

标签: iphone objective-c ios xcode

当应用程序启动时,我的项目中有一个Intro影片,顺便说一下我使用storyboard,然后我将MovieVC作为初始视图,所以当应用程序启动时,当您按下或电影结束时会显示MovieVC,它将显示RootVC。它在我测试时在simulatordevice中工作,但当我使用instruments使用Leaks对其进行测试时,发现了内存泄漏。

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

希望有人能帮助解决我的错误。三江源。

1 个答案:

答案 0 :(得分:1)

我建议尝试使用设备运行仪器......因为以前存在库本身的问题。 如果在设备上泄漏消失,那么你很高兴... :)