Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can release MPMoviePlayerController preload memory
    text
    copied!<p>HELLO. I'm using a MPMoviePlayerController in my iPhone app to display some short video clips sometimes. There are some buttons in the app mainView . When I press the button, the movie will be play. When I press the button,the button call [self playVideo: @"xxx"],and the video shows correctly.<strong>But when I see the app with Instruments Allocations Tool I see that the memory allocated gets up to 8+ MB and is not deallocated after the player finished.</strong> if I press the button just about 15th times, the ipad will collapse. The responsible for the allocations is a responsible Library called <strong>CoreVideo</strong> . Maybe the memory leaks when the video preload but don't release after it's finished. How i can release these memory. Here are the methods in the Category:</p> <pre><code>-(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]; } </code></pre> <p>Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload