Reputation: 21
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
Upvotes: 1
Views: 481
Reputation: 1716
Uncheck Enable Zombie Objects option under Edit Scheme. And try again.
Upvotes: 0
Reputation: 15512
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];
}
Upvotes: 2