2

是代码的MPMoviePlayerController释放问题

- (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,甚至释放后停留在那里,这是否意味着内存没有得到释放?

+0

我无法找到答这个阙任何地方 – Nnp 2010-02-02 19:24:39

+0

一年后,你找到答案? – 0xDE4E15B 2011-01-31 21:38:46

回答

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]; 

然后再试一次。