I am runung Instruments on an iPhone 4S. I am using AVAudioPlayer inside this method:
-(void)playSound{
NSURL *url = [self.word soundURL];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
if (!error) {
[audioPlayer prepareToPlay];
[audioPlayer play];
}else{
NSLog(@"Problem With audioPlayer on general card. error : %@ | url %@",[error description],[url absoluteString]);
}
I am getting leaks when playing the sound files:
Leaked objects:
1.
Object: NSURL
Responsible Library: Foundation
Responsable Frame: Foundation -[NSURL(NSURL) allocWithZone:]
2.
Object: _NSCFString
Responsible Library: Foundation
Responsable Frame: Foundation -[NSURL(NSURL) initFileURLWithPath:]
Instruments does not point directly to my code so I find it hard to locate the leak reason.
MY QUESTION
What could cause the leak? OR How can I locate leaks when I am not responsible to the code?
EDIT This is the schema from Instruments cycles view: Thanks Shani
error
tonil
, but you later test for!error
. (APIs that take anNSError **
return are not guaranteed to seterror
unless the call fails. You must checkaudioPlayer != nil
before usingerror
. You should also initializeerror
to nil. – nielsbotAVAudioPlayer
instance 1. retains the passed in data/url and 2. creates an instance ofAVAudioPlayerCpp
which 3) also retains the passed in data/url. When theAVAudioPlayer
is released, it releases the data/url, but I never see a release from the associatedAVAudioPlayerCpp
– nielsbot