【问题标题】:MPMoviePlayerController: high usage of memory (not deallocated)MPMoviePlayerController:内存使用率高(未释放)
【发布时间】: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


    【解决方案1】:

    该问题的解决方案似乎是这样的: 您必须在发布之前致电[player stop]。这似乎有点奇怪,因为我已经收到有关播放器完成播放的通知。这样做内存会被释放(只剩下少量,CoreMedia 大约 100Kb,但我相信这是正常的

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-10
      • 1970-01-01
      • 2020-05-21
      • 1970-01-01
      • 2019-05-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多