2012-09-26 147 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

我會建議嘗試使用設備來運行儀器......因爲之前的庫本身存在一些問題。 如果在設備上泄漏消失,那麼你很好去.. :)