Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-12-2010, 04:06 AM   #1 (permalink)
Divine avenger
 
Johanovski's Avatar
 
Join Date: Nov 2009
Location: Vic, Catalunya (Spain)
Posts: 320
Default Releasing a MPMoviePlayerController...

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:

Code:
...[1163:207] RT:2
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!
Johanovski is offline   Reply With Quote
Reply

Bookmarks

Tags
leak, mpmovieplayercontroller, release, retaincount

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 242
24 members and 218 guests
ADY, AragornSG, bookesp, chillyh, dacapo, Dani77, Davey555, Dominus, dre, glenn_sayers, HemiMG, JasonR, karlam963, M.A.S., marshusensei, mer10, nobre84, Oral B, prchn4christ, Raggou, Rudy, spiderguy84, themathminister, viniciusdamone
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,765
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:25 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0