views:

132

answers:

1

My movie player leaks memory only on the iPad and only when the "Done" button is clicked. If the movie plays to completion then it cleans itself up properly. Here is the play code:

mViewPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[self movieURL:@"mymovie"]];
[self.parentViewController presentModalViewController:mViewPlayer animated:YES];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitedFullscreen:) name:MPMoviePlayerPlaybackDidFinishNotification object:[mViewPlayer moviePlayer]];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitedFullscreen:) name:MPMoviePlayerDidExitFullscreenNotification object:[mViewPlayer moviePlayer]];

And here is the cleanup code:

- (void)exitedFullscreen:(NSNotification*)aNotification 
{
 MPMoviePlayerController *player = [aNotification object];
 [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
 [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:player];

 [self.parentViewController dismissModalViewControllerAnimated:YES];
 NSLog(@"retainCount theMovie: %i", [mViewPlayer retainCount]); 
 player.initialPlaybackTime = -1;
 [player pause];
 [player stop];
 NSLog(@"retainCount theMovie: %i", [mViewPlayer retainCount]); 
 [player release];
 player = nil;
// [mViewPlayer release];
 mViewPlayer = nil;
}

retainCount is 3 both times it is printed above and is the same when the movie completes normally or when the "Done" button is clicked.

I have tried using MPMoviePlayerController as well with the same results. I have tried using prepared play and 10 different methods to call the MPMoviePlayer*Controller, but it always leaks when I click the Done button.

Any help would be greatly appreciated. Thanks.