views:

85

answers:

1

This is code from Apple's Addmusic example.

MPMediaPickerController *picker =
    [[MPMediaPickerController alloc] initWithMediaTypes: MPMediaTypeMusic];

picker.delegate                        = self;
picker.allowsPickingMultipleItems    = YES;
picker.prompt                        = NSLocalizedString (@"Add songs to play", "Prompt in media item picker");

// The media item picker uses the default UI style, so it needs a default-style
//        status bar to match it visually
[[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleDefault animated: YES];

[self presentModalViewController: picker animated: YES];
[picker release];

I'm using this code in my app and the Leaks instrument highlights a leak on the line:

[self presentModalViewController: picker animated: YES];

I think that this is because this line retains a reference to picker which cannot be subsequently released.

Is there any way around this or is Leaks incorrectly identifying a leak?

A: 

It can be released by a call to dismissModalViewControllerAnimated:

invariant
So does that mean that Instruments has incorrectly identified a leak because I do dismissModalViewControllerAnimated: later in the code?
Joe
I'm not sure. I'm wondering why the [picker release] line is there though, why would the calling code be releasing it if it hasn't retained it?
invariant
picker is retained with the [MPMediaPickerController alloc] line so it has to be released with [picker release]
Joe
yep gotcha, just ignore me :)
invariant