0

Can anyone tell me why I show a memory leak in instruments when I play a video? movieURL and moviePlayer are both retained, synthesized properties that are later released in dealloc. Thanks in advance for your help.

- (void)playMovie:(NSString *)movieString { 
NSLog(@"playMovie movieString: %@",movieString);
self.movieURL = [Utilities localMovieURLForFileName:movieString];
if (self.movieURL) {
    MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:self.movieURL];
    [[mp view] setFrame: [self.view bounds]];  // frame must match parent view
    [self.containerViewController.view addSubview: [mp view]];

    if (mp)
    {
            //save the movie player object
        self.moviePlayer = mp;
        [mp release];
        [self setUpMoviePlayer];

            // Apply the user specified settings to the movie player object
            //[self setMoviePlayerUserSettings];

            // Play the movie!
        [self.moviePlayer play];
    }
}
self.movieURL = nil;

}

2 Answers 2

0

The [mp release]; line does not need to be in the if statement. In Objective-C, you can send message to nil. So if your object was not allocated, that line won't crash as the init method will return nil.

Maybe that's why Instruments reports a memory leak, as it can't be assured your condition is met.

But your code seems to be valid. Also checks your properties, for copy or retain.

1
  • As long as you release them in your dealloc method, yes
    – Macmade
    Mar 6, 2011 at 10:08
0

Instrument does tell you which line it was leaking memory so probably you could just pin down the line and tell us. In fact i think the whole if statement could be placed outside.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.