1

I'm using MPMoviePlayerController play online video (I'm using ARC), here's the code:

_moviePlayer = [[ZXMPMoviePlayerController alloc] init];
_moviePlayer.view.frame = CGRectMake(0, 100, 320, 320);
_moviePlayer.controlStyle = MPMovieControlStyleNone;
[self.view addSubview:_moviePlayer.view];
NSString *sourcePathStr = @"";  //video url
_moviePlayer.contentURL = [NSURL URLWithString:sourcePathStr];
_moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[_moviePlayer prepareToPlay];
[_moviePlayer play];

ZXMPMoviePlayerController is a subclass of MPMoviePlayerController in case of observing the deallocation of _moviePlayer.

Now I'm sure _moviePlayer is deallocated(because I printed log in dealloc method of ZXMPMoviePlayerController) after I leave this VC (VC is deallocated also.), but the memory usage of my app is still high, This is a test demo, the vc is clean except the movieplayer. I think it must be something of _moviePlayer is still in memory, like cache of something else, I have no idea...

Any ideas? Help...

in .h

@interface ZXMPMoviePlayerController : MPMoviePlayerController

@end

in .m #import "ZXMPMoviePlayerController.h"

@implementation ZXMPMoviePlayerController


- (void)dealloc
{
    NSLog(@"%s",__FUNCTION__);
}

@end
Cilitie
  • 21
  • 4
  • Are you using "NSZombie" enabled in your project(under "EditSchemes")? – Yogendra Sep 11 '14 at 09:09
  • @Student yes, I am. and I found out that whether NSZombie is enabled doesn't affect the memory usage too much. – Cilitie Sep 11 '14 at 13:56
  • Ok then disable it, and check again. For more information check my answer here http://stackoverflow.com/questions/25521856/memory-not-being-released-right-even-dealloc-method-is-called-after-dismissing-v/25521933#25521933 – Yogendra Sep 11 '14 at 13:59
  • @Student yeah, the memory is lower than before, but still cannot be released after the movieplayer deallocated. I'm not so familiar with Instruments, how could I know what exactly are keeping those memory? Living bytes, responsible caller, or category , none of them I could find any clue... Thankyou! – Cilitie Sep 12 '14 at 06:45
  • Some links for you. hope it help http://www.raywenderlich.com/23037/how-to-use-instruments-in-xcode https://developer.apple.com/library/mac/documentation/developertools/conceptual/instrumentsuserguide/Introduction/Introduction.html – Yogendra Sep 12 '14 at 06:50

2 Answers2

2

Hi to be sure that you release memory wrap all code with @autoreleasepool. In the dealloc you should clean your memory. When you are using dealloc method you should check if all object are release to avoid memory leaks.

- (void)dealloc
{
   [moviePlayer_ release];
    moviePlayer_ = nil;
}

This how you should call video player.

@autoreleasepool
{

    [_moviePlayer release];
    _moviePlayer = nil;

    _moviePlayer = [[ZXMPMoviePlayerController alloc] init];
    _moviePlayer.view.frame = CGRectMake(0, 100, 320, 320);
    _moviePlayer.controlStyle = MPMovieControlStyleNone;
    [self.view addSubview:_moviePlayer.view];
    NSString *sourcePathStr = @"";  //video url
    _moviePlayer.contentURL = [NSURL URLWithString:sourcePathStr];
    _moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
    [_moviePlayer prepareToPlay];
    [_moviePlayer play];


}
Oleg Gordiichuk
  • 15,240
  • 7
  • 60
  • 100
0

Uncheck Enable Zombie Objects option under Edit Scheme. And try again.

Yogendra
  • 1,728
  • 16
  • 28