[英]Memory leak in MPMoviePlayerController
谁能告诉我为什么我在播放视频时乐器上出现内存泄漏? movieURL和moviePlayer都是保留的综合属性,稍后将在dealloc中发布。 在此先感谢您的帮助。
- (void)playMovie:(NSString *)movieString {
NSLog(@"playMovie movieString: %@",movieString);
self.movieURL = [Utilities localMovieURLForFileName:movieString];
if (self.movieURL) {
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:self.movieURL];
[[mp view] setFrame: [self.view bounds]]; // frame must match parent view
[self.containerViewController.view addSubview: [mp view]];
if (mp)
{
//save the movie player object
self.moviePlayer = mp;
[mp release];
[self setUpMoviePlayer];
// Apply the user specified settings to the movie player object
//[self setMoviePlayerUserSettings];
// Play the movie!
[self.moviePlayer play];
}
}
self.movieURL = nil;
}
[mp release];
行不需要在if
语句中。 在Objective-C中,您可以将消息发送到nil
。 因此,如果未分配对象,则该行不会崩溃,因为init
方法将返回nil
。
也许这就是为什么Instruments报告内存泄漏的原因,因为不能保证满足您的条件。
但是您的代码似乎有效。 还检查您的属性,以进行copy
或retain
。
Instrument确实会告诉您它正在泄漏内存的那条线,因此可能您只需固定一下线并告诉我们即可。 实际上,我认为整个if语句都可以放在外面。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.