views:

94

answers:

1

I'm using a MPMoviePlayerController in my iPhone app to display some short video clips sometimes. I deaclared a Category which ads a couple methods to the class to properly attach its view to a particular view and to remove it from there. I use the notification system to let a class know when the movie has finished playing, then I try to remove it. Here are the methods in the Category:

- (void)setViewInCurrentController{  
    LPAppDelegate * appDelegate = [[UIApplication sharedApplication] delegate];
    self.view.frame = CGRectMake(0, 0, 320, 480);
    self.view.alpha = 0.0;

    [appDelegate.window addSubview:self.view];
    [UIView beginAnimations:@"FadeIn" context:nil];
    [UIView setAnimationDuration:0.3];
    [UIView setAnimationBeginsFromCurrentState:YES];
    self.view.alpha = 1.0;
    [UIView commitAnimations];

}
- (void)removeViewInCurrentController{

    [UIView beginAnimations:@"FadeOut" context:nil];
    [UIView setAnimationDuration:0.3];
    [UIView setAnimationBeginsFromCurrentState:YES];
    self.view.alpha = 0.0;
    [UIView setAnimationDelegate:self];
    [UIView setAnimationDidStopSelector:@selector(removeFromSuperview)];
    [UIView commitAnimations];
} 

And here is where I use the MPMoviePlayer:

- (void)playVideoNarration:(VideoNarration *)vNarr{
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] 
                                       initWithContentURL:[NSURL fileURLWithPath:vNarr.videoURI]];
    [[NSNotificationCenter defaultCenter] 
                             addObserver:self
                                selector:@selector(videoNarrationFinishedPlaying:)                                                 
                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                  object:player];

    [player setViewInCurrentController];
    player.controlStyle = MPMovieControlStyleNone;
    [player play]; 
}

- (void)videoNarrationFinishedPlaying:(NSNotification *) aNotification{

    MPMoviePlayerController * player = [aNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:player];
    [player removeViewInCurrentController];
    [player release];
}

The video shows correctly and then the player gets removed from the view and I guess it gets deallocated too, but when I see the app with Instruments Allocations Tool I see that the memory allocated gets up to 20+ MB and is not deallocated after the player finished. The responsible for the allocations is a lib called VideoToolBox.

No leaks are shown except some from a library called AudioToolBox. Any guess on what is happening?

A: 

The solution for that problem seems to be this: you have to call the [player stop] before releasing it. It appears a little strange since I'm already receiving a notification about the player finished playing. Doing so the memory gets deallocated (only a small amount remains , ~100Kb from CoreMedia, but I believe is it normal

rano