MPMoviePlayerController is still leaking

I release MPMoviePlayerController, but memory allocation and live objects are still higher than before allocating the object. However, if I redistribute the object, it no longer flows. My application actually uses a lot of media files, and the memory consumption is high. I would like to completely free up unnecessary memory in order to avoid memory warnings.

Movie Release:

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

Video player placement:

    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];
+3
source share
3 answers

I also had this problem.

, iPad , . , , . 50 .

:

, . , , , , , , , ....!

tweeking , , :

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

    [[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 - , .

2 -

3 -

4 -

5 - ,

6 -

7 - , ,

-, iPad (OS 4.2). , , . .

, ...

+4

(Build > Build and Analyze), , ( ).

, NSURL.

0

? (, AudioToolbox, CoreVideo ..). , , , , , .

mp4, , (10 , , ... 20 , 5 ). .

However, on my iPhone (with 20 MB video), it allocated only 900 KB of shared memory for the application, with no noticeable changes when starting / stopping / releasing the video. It always remained approximately 900 kb for 10 times when I tested it (start / stop / release).

It looks like the next time you won’t be able to trust the simulator.

Code I tested:

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"SomeMovieFile" ofType:@"mp4"]];

MPMoviePlayerController *newPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

self.player = newPlayer;  
[newPlayer release];

[self.view addSubview:player.view];  // for my example, I didn't set the frame location, but no difference that would do
[player play];

Then in another button I stopped it and released the player:

[player.view removeFromSuperview];    
player.initialPlaybackTime = -1;
[player stop];
self.player = nil;  // this is just a habit of mine.. calling stop should unload the buffers though
[player release];
0
source

Source: https://habr.com/ru/post/1757589/


All Articles