我的项目使用ARC。我想在按下按钮时播放电影。目前我的代码调出一个电影播放器并正确播放电影。解除MPMoviePlayerController视图后,它将返回原始视图。如果我点击原始视图上的后退按钮,它将不会被释放并保留在内存中。如果我从不按下按钮来播放电影,它将被正确释放。
在.h
中声明@property (strong,nonatomic) MPMoviePlayerViewController * moviePlayerController;
用.m:
调出电影 -(IBAction)playMovie:(NSURL *) theURL
{
NSURL *fileURL = [[NSURL alloc] initWithString:movieTrailerURL];
self.moviePlayerController = [[MPMoviePlayerViewController alloc] initWithContentURL:fileURL];
[moviePlayerController.moviePlayer prepareToPlay];
//moviePlayerController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[self presentViewController:moviePlayerController animated:YES completion:nil];
}
当通过结束或按下完成按钮解除电影时,这称为
- (void)moviePlaybackComplete:(NSNotification *)notification
{
NSLog(@"I am in movie playback complete!!!");
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
// [moviePlayerController.moviePlayer pause];
// moviePlayerController.moviePlayer.initialPlaybackTime = -1;
// [moviePlayerController.moviePlayer stop];
// moviePlayerController.moviePlayer.initialPlaybackTime = -1;
//[moviePlayerController.moviePlayer.view removeFromSuperview];
// [moviePlayerController.view removeFromSuperview];
// [moviePlayerController.moviePlayer release];
}
我已经尝试了注释掉的部分的每个组合来尝试让我的moviePlayerController从内存中释放,以便父视图将释放和释放。
答案 0 :(得分:-1)
您正在使用self.propertyname分配属性,它会将保留计数更改为“2”因为当它在.m类中进行@synthesize时,其保留计数也会增加1。所以尝试在没有self的情况下分配属性,或者只将它作为全局变量而不是属性。