开发者

Huge memory leak after using MPMoviePlayerController

I've come across this 3MB malloc done by CoreVideo on my iPad app after releasing an MPMoviePlayerController object.

I've made sure that the player is stopped before released, so it does actually release memory and deallocs properly. The thing is that instruments keeps showing this malloc that hasn't been released (and is not used directly by me in my code) This is the call that's shown in instruments as responsible caller for the 3.52MB Malloc that's never released.

CVPixelBufferBacking::initWithPixelBufferDescription

Here's the code where the players are stopped and the array that contains them released

- (void)dealloc {
...


[self stopAllPlayers];
[_moviePlayerViewControllerArray release];

[super dealloc];
}

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

    }
}

here's the method that adds the video

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



 ......

    MPMoviePlayerController * movieCo开发者_高级运维ntroller= [[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];

}

EDIT: added image

Huge memory leak after using MPMoviePlayerController

. the beautiful 3MB malloc in all it's glory.

Huge memory leak after using MPMoviePlayerController

as you can see the other chunk of memory is no longer there but I still have a major problem. thanks in advance for your help


do you do

[movieController.view removeFromSuperview]

somewhere ?


add a movie finished callback this way -

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:[playerViewController moviePlayer]];

and release and remove the player in this callback method -

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


I finally nailed this issue. When I tested out the app on the device, what was supposed to be a leak on CoreVideo changed its name to "". Lurking a little bit around certain forums, I found this is cause mainly by Core Graphic "objects" being autoreleased but never deallocated by the auto release pool.

Basically Wherever I created and used Core Graphics objects, I added NSAutoReleasePool objects to dispose the CG objects in a timely manner.

Thank you very much for you answers. And specially to Bastian for his comment on my question that was key to solve this issue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜