MPMoviePlayerController仍在泄露 [英] MPMoviePlayerController still leaking

查看:107
本文介绍了MPMoviePlayerController仍在泄露的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发布了MPMoviePlayerController但是内存分配和活动对象仍然高于对象分配之前。但是,如果我重新分配对象,它不会泄漏更多。
我的应用程序实际上使用了大量的媒体文件,内存消耗很高。我想完全释放不必要的内存以避免内存警告。

I release the MPMoviePlayerController but the memory allocation and the living objects are still higher than before the object allocation. However if I reallocate the object it doesn't leak more. My application actually uses a lot of media files and the memory consumption is high. I would like to free up completely the unneeded memory to avoid memory warnings.

电影播放器​​发布:

        player.initialPlaybackTime = -1;
        [player.view removeFromSuperview];
        [player stop];
        [player release];

电影播放器​​分配:

    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"video0_hd.mov" ofType:nil]];
    player = [[MPMoviePlayerController alloc] initWithContentURL:url];
    player.view.frame = placeholder.frame;
    [self.view addSubview:player.view];
    [player play];


推荐答案

我也有这个问题。

iPad用于预加载视频流的缓存未完全清空。
所以每次这个带有视频播放器的页面都被清理并释放,清理后分配的内存仍然包含缓存的内存。对于大视频,这可能高达50 MB。

The cache used by the iPad for preloading the video stream, was not emptied completely. So each time, this page with the video player was cleaned up and released, the allocated memory after cleanup still contained the cached memory. For big video's, this could be up to 50 MB.

这实际上不是内存泄漏:

This is actually not a memory leak:

如果再次打开页面,则重新分配缓存。但是仍然令人沮丧,因为你想要一个干净的退出情况,这意味着当这个页面被留下并清理时,应该释放这个页面使用的所有内存,包括用于缓存视频流的内存....!

If the page was opened again, the cache was re-allocated. But still frustating as you want a clean exit situation, meaning when this page is left and cleaned up, all memory used by this page should be released, including the memory used for caching the video stream....!

经过一些严肃的推文后,这一系列命令似乎可以完成这项任务:

After some serious tweeking, this sequence of commands seems to do the job:

========== ============

======================

    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:myMoviePlayer];        

    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerDidExitFullscreenNotification
                                                  object:myMoviePlayer];        

    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerLoadStateDidChangeNotification
                                                  object:myMoviePlayer];

    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMovieDurationAvailableNotification
                                                  object:myMoviePlayer];        
    [myMoviePlayer pause];
    myMoviePlayer.initialPlaybackTime = -1;
    [myMoviePlayer stop];
    myMoviePlayer.initialPlaybackTime = -1;
    [myMoviePlayer.view removeFromSuperview];
    [myMoviePlayer release];

===================== ============

=================================

步骤:

1 - 删除所有通知程序您正在使用电影播放器​​。

1 - REMOVE all notifiers you are using for your movie player.

2 - 暂停电影

3 - 将播放时间设置为开始

3 - set the Playback time to start

4 - 停止播放电影

4 - stop the movie

5 - 再次设置播放时间以开始

5 - set the Playback time again to start

6 - 现在删除电影查看

6 - now remove the movie View

7 - 最后发布电影播放器​​

7 - and finally release the movie player

导致我的情况也在我的iPad上发布的视频缓存(OS 4.2。)
并留下一个干净的分配内存情况,等于播放视频播放器的页面之前的大小。所以相同的进入和退出记忆。

Resulting in my case in also the video cache memory being released on my iPad (OS 4.2.) and leaving a clean allocated memory situation, equal to the size before the page with the video player was openen. So same enter and exit memory.

希望这有帮助......

Hope this helps......

这篇关于MPMoviePlayerController仍在泄露的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆