On 28/08/2010, at 11:11 PM, Michael Crawford wrote:

> My question is this: is my technique for releasing the only reference I have 
> to the movie controller, which is the notification object, valid?  NOTE: This 
> is the new 3.2 SDK movie player controller.
> 
> - (BOOL)application:(UIApplication*)application 
> didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
> {
>    // start playback of intro movie and watch for notification of playback 
> completion
>    MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] 
> initWithContentURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] 
> pathForResource:@"intro_movie" ofType:@"mp4"]]];


You are tying yourself in knots thinking about how the notification center 
might or might not be holding references to 'moviePlayer'. It's much simpler - 
you created it (alloc + init) therefore you own it. It is thus up to you to 
release it when you've finished with it.

Don't think in terms of incrementing and decrementing retain counts, just think 
about who owns what.

I wouldn't rely on NSNotificationCenter taking ownership of this object - in 
fact it's almost certain it does not (though it's an implementation detail 
you're not party to). The safest, sanest, conventional thing to do is to hold a 
reference to the player as an ivar and release it when it finishes. Why go to a 
lot of trouble to avoid doing that? Its cost is minute.

--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to