【问题标题】:MPMoviePlayerController release problemMPMoviePlayerController 发布问题
【发布时间】:2011-01-11 21:08:53
【问题描述】:

这里是代码

- (void)applicationDidFinishLaunching:(UIApplication *)application {
  NSBundle *bundle = [NSBundle mainBundle];
 NSString *moviePath = [bundle pathForResource:@"sample_mpeg4" ofType:@"mp4"];
 NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];


 MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
 moviePlayer.movieControlMode =   MPMovieControlModeHidden;

 [moviePlayer play];

 [[NSNotificationCenter defaultCenter] addObserver:self 
 selector:@selector(moviePlaybackDidFinish:) 
 name:MPMoviePlayerPlaybackDidFinishNotification 
 object:nil]; 

 }
- (void) moviePlaybackDidFinish:(NSNotification*)notification
 {

MPMoviePlayerController *theMovie = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self                                      name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:theMovie];
[theMovie stop];
[theMovie release];

[window addSubview:tabBarController.view];
[window makeKeyAndVisible];
}

所以我的问题是我的应用程序内存使用量增加了 3MB,即使在释放后它仍然存在,这是否意味着内存没有被释放?

【问题讨论】:

  • 我在任何地方都找不到这个问题的答案
  • 一年后,你找到答案了吗?

标签: iphone performance memory memory-leaks mpmovieplayercontroller


【解决方案1】:

看看你的代码

- (void) moviePlaybackDidFinish:(NSNotification*)notification
MPMoviePlayerController *theMovie = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self                                      name:MPMoviePlayerPlaybackDidFinishNotification                                             object:theMovie];

您确定“theMovie”是您创建的“moviePlayer”吗?我相信它们是不同的内存地址,因为您在注册通知时没有分配对象。确定

 [[NSNotificationCenter defaultCenter] addObserver:self 
 selector:@selector(moviePlaybackDidFinish:) 
 name:MPMoviePlayerPlaybackDidFinishNotification 
 object:moviePlayer];

然后再试一次。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多