HELLO입니다. 때때로 짧은 비디오 클립을 표시하기 위해 iPhone 응용 프로그램에서 MPMoviePlayerController를 사용하고 있습니다. 앱 mainView에 몇 가지 버튼이 있습니다. 버튼을 누르면 동영상이 재생됩니다. 버튼을 누르면 버튼이 [self playVideo : @ "xxx"]를 호출하고 비디오가 올바르게 표시됩니다. 그러나 계기 할당 도구로 앱을 볼 때 할당 된 메모리가 최대 8MB 이상이되고 플레이어가 끝나면 할당이 해제되지 않습니다. 버튼을 약 15 번 누르면 ipad가 무너집니다. 배정 책임자는 CoreVideo이라는 책임있는 도서관입니다. 비디오가 미리로드 될 때 메모리 누수가 발생하지만 완료된 후에도 해제되지 않을 수 있습니다. 이 메모리를 어떻게 풀 수 있습니까? 다음은 카테고리의 방법은 다음과 같습니다MPMoviePlayerController 미리로드 메모리를 해제하는 방법은
-(id)playVideo:(NSString*)videoName
{
NSString* s = [[NSBundle mainBundle] pathForResource:videoName ofType:@"mp4"];
NSURL* url = [NSURL fileURLWithPath:s];
[self playVideoAtURL: url];
s = nil;
[s release];
url = nil;
[url release];
}
-(void)playVideoAtURL:(NSURL *)theURL
{
theMovie = [[MPMoviePlayerViewController alloc] initWithContentURL:theURL];
theMovie.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
theMovie.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
if (LeftOrRight == 0) {
[theMovie.view setTransform: CGAffineTransformMakeRotation(degreesToRadians(-90))];
}
else if (LeftOrRight == 1) {
[theMovie.view setTransform: CGAffineTransformMakeRotation(degreesToRadians(90))];
}
CGRect screenBounds = [[UIScreen mainScreen] bounds];
theMovie.view.frame = screenBounds;
theMovie.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[theMovie.moviePlayer prepareToPlay];
[self presentModalViewController: theMovie animated: YES];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedCallback:)
name: MPMoviePlayerPlaybackDidFinishNotification
object:nil];
}
-(void)myMovieFinishedCallback:(NSNotification *)aNotification
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[theMovie dismissMoviePlayerViewControllerAnimated];
[theMovie.moviePlayer stop];
[theMovie release];
}
감사합니다!