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

然後再試一次。