【发布时间】:2010-08-19 07:24:13
【问题描述】:
我有时在我的 iPhone 应用程序中使用 MPMoviePlayerController 来显示一些短视频剪辑。我声明了一个 Category ,它向该类添加了几个方法,以正确地将其视图附加到特定视图并从那里删除它。 我使用通知系统让班级知道电影何时播放完毕,然后我尝试将其删除。 以下是 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];
}
这里是我使用 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];
}
视频正确显示,然后播放器从视图中删除,我猜它也被释放了,但是当我看到带有 Instruments Allocations Tool 的应用程序时,我看到分配的内存达到 20+ MB 并且没有释放玩家完成后。 负责分配的是一个名为 VideoToolBox 的库。
除了来自名为 AudioToolBox 的库中的一些泄漏外,没有显示任何泄漏。猜猜发生了什么?
【问题讨论】:
标签: iphone memory-leaks memory-management mpmovieplayercontroller