开发者

MPMoviePlayerViewController memory problem

开发者 https://www.devze.com 2023-01-31 11:26 出处:网络
I have a problem with MPMoviePlayerViewController on iPad iOS 4.2. An application plays a video, but when the video stops the memory doesn\'t released.

I have a problem with MPMoviePlayerViewController on iPad iOS 4.2. An application plays a video, but when the video stops the memory doesn't released. To create a video player I use the following code:


    MPMoviePlayerViewController * videoPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:articleUrl];
    [videoPlayer moviePlayer].movieSourceType = MPMovieSourceTypeFile;
    [videoPlayer moviePlayer].controlStyle = MPMovieControlStyleDefault;
    [videoPlayer moviePlayer].scalingMode = MPMovieScalingModeAspectFit;
    [videoPlayer moviePlayer].fullscreen = NO;

    self.playerViewController = videoPlayer;
    [videoPlayer release];
    videoPlayer = nil;

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

    MPMoviePlayerController *player = [playerViewController moviePlayer];

    CGRect playerFrame = CGRectMake(20, 20, self.view.frame.size.width - 40, self.view.frame.size.height - 40); 
    player.view.frame = playerFrame;
    [self.view addSubview:player.view];
    [player play];

and there is the movieFinishedCallback: method code:


    - (void) movieFinishedCallback:(NSNotification*) aNotification {
    MPMoviePlayerController *player = [aNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self 
                            开发者_C百科                        name:MPMoviePlayerPlaybackDidFinishNotification 
                                                  object:player];
    [player.view removeFromSuperview];
    [player release];
    player = nil;

}

Can anybody help me with it? I have read a lot of topics related to this problem, but haven't found solution.


Your code looks good - your releases match your retains etc.

Have you run this in Instruments - i.e. is it definitely a leak? How do you know that the memory is not being freed?

There's nothing wrong with the video playback framework keeping your video cached as long as it releases the memory if you run short (i.e. get a low memory warning). Try running it in the simulator and simulating a memory warning - I bet that the memory gets released then.

Also, you don't know if it's going to be autoreleased at any point.

I wouldn't be worried about this problem until you run into memory warnings. Until then, I'd just assume the video framework knows what it's doing!

0

精彩评论

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