Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 使用MPMoviePlayerController后出现巨大内存泄漏_Iphone_Objective C_Memory Management_Memory Leaks_Instruments - Fatal编程技术网

Iphone 使用MPMoviePlayerController后出现巨大内存泄漏

Iphone 使用MPMoviePlayerController后出现巨大内存泄漏,iphone,objective-c,memory-management,memory-leaks,instruments,Iphone,Objective C,Memory Management,Memory Leaks,Instruments,在发布MPMoviePlayerController对象后,我在iPad应用程序上遇到了CoreVideo完成的3MB malloc 我已经确保播放器在发布之前已经停止,所以它确实可以正确地释放内存和释放。问题是,instruments一直显示这个malloc,它还没有发布(我在代码中没有直接使用) 这是一个调用,在instruments中显示为从未发布的3.52MB Malloc的负责调用方 CVPixelBufferBacking::initWithPixelBufferDescriptio

在发布MPMoviePlayerController对象后,我在iPad应用程序上遇到了CoreVideo完成的3MB malloc

我已经确保播放器在发布之前已经停止,所以它确实可以正确地释放内存和释放。问题是,instruments一直显示这个malloc,它还没有发布(我在代码中没有直接使用) 这是一个调用,在instruments中显示为从未发布的3.52MB Malloc的负责调用方

CVPixelBufferBacking::initWithPixelBufferDescription
下面是停止播放机并释放包含播放机的数组的代码

- (void)dealloc {
...


[self stopAllPlayers];
[_moviePlayerViewControllerArray release];

[super dealloc];
}

-(void)stopAllPlayers {
    for (MPMoviePlayerController *mp in _moviePlayerViewControllerArray) {
        [mp stop];

    }
}
下面是添加视频的方法

-(void)addVideo:(NSString*) videoName onRect:(CGRect)rect {



 ......

    MPMoviePlayerController * movieController= [[MPMoviePlayerController alloc]initWithContentURL:(NSURL *)videoURL];

    // set frame for player
    movieController.view.frame = rect;

    // set  auto resizing masks
    [movieController.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];

    // don't auto play.
    [movieController setShouldAutoplay:NO];

    [pdfView addSubview:movieController.view];
    [pdfView bringSubviewToFront: movieController.view];


    [_moviePlayerViewControllerArray addObject:movieController];
    [movieController release];

}
编辑:添加图像。美丽的3MB malloc在所有它的荣耀

正如你所看到的,另一块内存已经不在了,但我仍然有一个大问题。 提前谢谢你的帮助

你呢

[movieController.view removeFromSuperview]
在什么地方?

你喜欢吗

[movieController.view removeFromSuperview]

某处?

以这种方式添加电影完成回调-

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:[playerViewController moviePlayer]];
并在此回调方法中释放并移除播放机-

- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player1 = [aNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification  object:player];
    [player1 stop];
    [player1.view removeFromSuperview];
    [player1 release];
}

以这种方式添加电影完成回调-

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:[playerViewController moviePlayer]];
并在此回调方法中释放并移除播放机-

- (void) movieFinishedCallback:(NSNotification*) aNotification {
MPMoviePlayerController *player1 = [aNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification  object:player];
    [player1 stop];
    [player1.view removeFromSuperview];
    [player1 release];
}

我终于解决了这个问题。当我在设备上测试该应用程序时,CoreVideo上本应存在的漏洞将其名称改为“”。在某些论坛中,我发现这主要是因为核心图形“对象”被自动释放,但从未被自动释放池释放

基本上,无论我在哪里创建和使用核心图形对象,我都会添加NSAutoReleasePool对象,以便及时处理CG对象


非常感谢您的回答。特别感谢巴斯蒂安对我的问题的评论,这是解决这个问题的关键。

我终于解决了这个问题。当我在设备上测试该应用程序时,CoreVideo上本应存在的漏洞将其名称改为“”。在某些论坛中,我发现这主要是因为核心图形“对象”被自动释放,但从未被自动释放池释放

基本上,无论我在哪里创建和使用核心图形对象,我都会添加NSAutoReleasePool对象,以便及时处理CG对象



非常感谢您的回答。特别感谢Bastian对我的问题的评论,这是解决这个问题的关键。

请用您的代码片段和仪器屏幕截图更新您的问题,也许我能帮您。嘿,我刚刚添加了代码片段和屏幕截图!:-)你是在设备上还是在模拟器上测试的?我认为电影控制器的情况有一些不同。事实上你是对的。我现在有一大块8MB的CoreGraphics,负责的调用者是CGDataProviderCreateWithFileName请用你的代码片段和仪器屏幕快照更新你的问题,也许我能帮你。嘿,我刚刚添加了代码片段和屏幕快照!:-)你是在设备上还是在模拟器上测试的?我认为电影控制器的情况有一些不同。事实上你是对的。我现在有一大块8MB的CoreGraphics,负责调用它的是CGDataProviderCreateWithFileName,为什么在它完成播放后要删除它?它可能处于全屏模式,如果立即删除可能会不好看,或者可能应该可以再次观看电影…我不想在完成电影播放后删除视图控制器。然后它将泄漏内存,因为您在电影结束后引用它。。。它违反了内存管理规则,即“removeFromSuperview”也将释放该对象,然后如果我们再次释放它,它将抛出exc错误访问,但其工作。。。我也很好奇!!当它完成播放时,为什么要删除它?它可能处于全屏模式,如果立即删除可能会不好看,或者可能应该可以再次观看电影…我不想在完成电影播放后删除视图控制器。然后它将泄漏内存,因为您在电影结束后引用它。。。它违反了内存管理规则,即“removeFromSuperview”也将释放该对象,然后如果我们再次释放它,它将抛出exc错误访问,但其工作。。。我也很好奇!!不,我只是把它放了。我要试试。不,我只是把它放了。我要试试看。