I was just talking about Memory Management this morning and now came across this problem. I have a sound that plays when a button is pushed. When I checked it in Instruments if found a memory leak. I found the problem to be the NSSound. The method is long but the problem part is in the beginning. The rest of the method is just getting int values from TextFields and doing math. Also I dragged the audio file into my project. and a pop up came up asking me to add it, which I did.
I did not NARC (NEW,ALLOC,RETAIN,COPY) so the Object dieRollSoundTwo should have been taken care of by the system as the method exited? It plays fine and I would never have guessed a memory leak existed until I tested it with Instruments.
Code:
- (IBAction)combatDieRoll:(id)sender {
NSSound *dieRollSoundTwo = [NSSound soundNamed:@"diceRollSound.aif"];
[dieRollSoundTwo play];
sleep(1);
dieRoll = arc4random() %100 +1;
....
...
..
}
I did not NARC (NEW,ALLOC,RETAIN,COPY) so the Object dieRollSoundTwo should have been taken care of by the system as the method exited? It plays fine and I would never have guessed a memory leak existed until I tested it with Instruments.