这是代码
- (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 :(得分: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];
然后再试一次。