私はARCを使用する非常にビデオの多いiPadのみのiOSアプリを開発していますが、MPMoviePlayerControllerを使用しようとするとリークがあるようです.instrumentは、ビデオプレーヤーオブジェクトにメモリを割り当てるコード行でメモリリークをスローします. ? また、ビデオの再生が完了したときに、ビデオ プレーヤーのクリーンアップが行われていないようです。
アプリケーションの性質上、問題が非常に大きな問題であることがわかるので、これに対する答えをどこでも探していました。
コード:
@interface ViewController ()
@property(nonatomic,strong) MPMoviePlayerController * vidPlayer;
@end
@implementation ViewController
@synthesize vidPlayer;
- (void)viewDidLoad
{
@autoreleasepool {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self playVideoForFile:@"01_intro"];
}
}
-(void)playVideoForFile:(NSString*)p_fileName
{
NSString *path = [[NSBundle mainBundle] pathForResource:p_fileName ofType:@"mp4"];
NSURL *tempURI = [NSURL fileURLWithPath:path];
vidPlayer = [[MPMoviePlayerController alloc] initWithContentURL:tempURI];
[vidPlayer setControlStyle:MPMovieControlStyleNone];
[vidPlayer setAllowsAirPlay:NO];
[vidPlayer.view setFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.height,[[UIScreen mainScreen] bounds].size.width)];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(vidFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:vidPlayer];
[vidPlayer play];
[self.view addSubview:vidPlayer.view];
}
-(void)vidFinishedCallback:(NSNotification*)aNotification
{
[vidPlayer pause];
vidPlayer.initialPlaybackTime = -1;
[vidPlayer stop];
vidPlayer.initialPlaybackTime = -1;
[vidPlayer.view removeFromSuperview];
vidPlayer = nil;
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:vidPlayer];
}