Hi all!
I'm using a MPMoviePlayerController just at the beginning of my app to show an intro, and after that I want to release the instance. I've tried calling a function with a timer and I thought this should did the trick, but after doing some tests and traces I've found that instance isn't being fully released and a some leaks appeared in the instruments. I'm showing you what I do:
// GameAppDelegate.h
Code:
(...some code...)
@interface OGLGameAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
EAGLView *glView;
MPMoviePlayerController *theMovie;
}
(...some code...)
// GameAppDelegate.m
Code:
(...some code...)
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];
NSBundle *bundle = [NSBundle mainBundle];
NSString *moviePath = [bundle pathForResource:@"test" ofType:@"m4v"];
NSURL *movieURL = [NSURL fileURLWithPath:moviePath];
theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
//NSURL *movieURL = [[NSURL fileURLWithPath:moviePath] retain];
//MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
theMovie.movieControlMode = MPMovieControlModeHidden;
[theMovie play];
[NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:@selector(endVideo) userInfo:nil repeats:NO];
glView.animationInterval = 1.0 / 60.0;
[glView startAnimation];
}
- (void) endVideo
{
[theMovie stop];
[theMovie release];
NSLog(@"RT:%d",[theMovie retainCount]);
}
(...some code...)
What trace show when movie should be released is the following:
But if I try to release theMovie 2 more times, after the function has ended seems that something tries to access the instance and it throws an error, which is the following with NSZombieEnabled:
Code:
...[1028:207] *** -[MPMoviePlayerController release]: message sent to deallocated instance 0x9438480
And, working with Instruments, 9 leaks appeared:
Leaked Object: NSCFString
#: 9
Address: <multiple>
Size: 1,62 KB
Responsible Library: Foundation
Responsible Frame: -[NSCFString
Does anyone knows what can be happening and what can I do to prevent this? I don't want to keep theMovie living during all game life, but I don't know how to make theMovie release itself or be released when it stops (I've also tried calling the "moviePlayBackDidFinish" method, but it never gets called...
Thanks in advance!