Hi all!
I'm having a problem with my app... I've been tracing memory leaks and solving them as I've found, but now I'm really stuck with it... I'll explain you what I'm doing and what is going wrong:
I've created a class called "Audio". This class have a property called "player" wich is a pointer to an AVAudioPlayer object:
************************************************** *************
interface Audio : NSObject {
NSString* label;
NSString* fileName;
NSString* fileType;
NSString* filePath;
NSURL* fileUrl;
AVAudioPlayer* player;
}
************************************************** *************
When this class inits calls it's own init method, wich is:
************************************************** *************
- (id)initAudio
{
[self init];
player = [[AVAudioPlayer alloc] init];
return self;
}
************************************************** *************
Then, another object called "Mosca" has a property wich is a pointer array to Audio objects, and Mosca's inits method has the following code:
************************************************** *************
(...)
for (int i=0; i<2; i++) {
sons[i] = [[Audio alloc] initAudio];
}
(...)
************************************************** *************
Everythings works fine, but when I try to release the objects the program gives me an EXC_BAD_ACCESS error near the [AVAudioPlayer release] method, and the way it gets there is the following:
************************************************** *************
// Mosca deallocation method
- (void) dealloc
{
//NSLog(@"dealloc mosca%d",_id);
for (int j=0; j<6; j++) {
[textures[j][0] release];
[textures[j][1] release];
[textures[j][2] release];
}
for (int i=0; i<2; i++) {
[sons[i] release];
}
[super dealloc];
}
--------------------------------------------------------------------------
// Audio's deallocation method:
- (void) dealloc
{
//NSLog(@"dealloc audio");
[label release];
[fileName release];
[fileType release];
[filePath release];
[fileUrl release];
[player release];
[super dealloc];
}
************************************************** *************
And then AVAudioPlayer has it's own deallocation method (wich is unaccessible for me because AVAudioPlayer is a part of the AVFoundation framework).
If i comment, for example, the [player release] command from the Audio deallocation method or the [sons[i] release] command from the Mosca deallocation method the program works fine and doesn't throw the EXC_BAD_ACCESS method, but then Instruments finds some leaks, all of them relating the initAudio method and pointing the [[AVAudioPlayer alloc] init] command.
Does anybody knows what can be happening? I'm really stuck with it...
Thanks in advance!