Проблема с выпуском MPMoviePlayerController - PullRequest
2 голосов
/ 01 февраля 2010

вот код

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

так что моя проблема в том, что использование памяти моих приложений увеличивается на 3 МБ, остается там даже после выпуска, значит ли это, что память не освобождается?

1 Ответ

1 голос
/ 04 июня 2010

Посмотрите на ваш код в

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

Тогда попробуйте еще раз.

...