2012-09-26 150 views
0

我有一个电影的介绍在我的项目时,应用程序启动时,我使用storyboard顺便说一下,然后我让我MovieVC作为初始视图,因此当应用程序启动时,显示的MovieVC那么当您按下或电影结束,它将显示RootVC。它在simulatordevice中工作,当我测试它时,但是当我使用Leaksinstruments进行测试时,发现了内存泄漏。avplayer内存泄露

我不知道什么是错,我使用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

在viewDidLoad方法的顶部添加[super viewDidLoad]并删除不需要的[super viewDidLoad]行,因为你已经使用了两次。 –

+0

您能更具体地了解仪器泄露的内容吗? –

+0

@CarlVeazey我已经使用'Leaks',这是我的另一个问题连接到这个---> http://stackoverflow.com/questions/12581164/detecting-fixing-memory-leaks – Bazinga

回答

1

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