2011-03-06 5 views
0

비디오를 재생할 때 악기에서 메모리 누수가 나타나는 이유는 누구에게 말해 줄 수 있습니까? movieURL 및 moviePlayer는 모두 dealloc에서 나중에 릴리스되는 합성 속성이 유지됩니다. 귀하의 도움에 미리 감사드립니다.MPMoviePlayerController에서 메모리 누수가 발생했습니다.

- (void)playMovie:(NSString *)movieString { 
NSLog(@"playMovie movieString: %@",movieString); 
self.movieURL = [Utilities localMovieURLForFileName:movieString]; 
if (self.movieURL) { 
    MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:self.movieURL]; 
    [[mp view] setFrame: [self.view bounds]]; // frame must match parent view 
    [self.containerViewController.view addSubview: [mp view]]; 

    if (mp) 
    { 
      //save the movie player object 
     self.moviePlayer = mp; 
     [mp release]; 
     [self setUpMoviePlayer]; 

      // Apply the user specified settings to the movie player object 
      //[self setMoviePlayerUserSettings]; 

      // Play the movie! 
     [self.moviePlayer play]; 
    } 
} 
self.movieURL = nil; 

}

답변

0

[mp release]; 라인이 if 문에있을 필요가 없습니다. Objective-C에서 nil으로 메시지를 보낼 수 있습니다. 따라서 객체가 할당되지 않은 경우 init 메서드는 nil을 반환하므로 해당 행은 충돌하지 않습니다.

어쩌면 인스 트루먼 트가 귀하의 조건이 충족되지 않을 수도 있기 때문에 메모리 누수를보고하는 이유 일 수 있습니다.

하지만 코드가 유효 할 것 같습니다. 속성도 확인하십시오 (copy 또는 retain).

+0

감사합니다. 속성은 retain입니다. 맞아, 맞지? – intomo

+0

dealloc 메소드에서 해제하는 한, 예 – Macmade

0

악기가 어떤 라인에서 메모리를 누설했는지 알려주므로 아마도 라인을 고정하고 알려줄 수 있습니다. 사실 나는 전체 if 문을 외부에 배치 할 수 있다고 생각합니다.

관련 문제