我正在開發一個非常重視iPad的視頻沉重的iOS應用程序,它使用ARC,但似乎我有一個泄漏當我嘗試使用MPMoviePlayerController,儀器引發內存泄漏的代碼行,分配內存的視頻播放器對象,任何想法?當視頻完成播放時,清理視頻播放器似乎也不會發生。MPMoviePlayerController導致泄漏
任何幫助將是非常讚賞,到處找這個答案,你可以告訴這個問題是非常多的顯示塞與應用程序的性質。
代碼:
@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];
}
你可以發佈儀器結果的屏幕截圖嗎? – Squatch 2012-04-16 17:30:45