1

I am developing a quiz app. I take questions from a xml file, parse it and display random questions. These are stored in NSdictionary and NSMutableArray. Also the app plays background music and sound for clicking of buttons(AVAudioPlayer). and vibration( AudioServicesPlaySystemSound(kSystemSoundID_Vibrate))

In one particular function if i try to release the temp variables that I use(I.E NSDictionary and NSMutableArray) the app crashes wen i reach that function for the second time. Hence if i don release these, it works fine but eventually crashes with a "EXC_BAD_ACCESS" ERROR. It does not point out to any line or function.

When i used the tool "LEAKS", it showed i was having around 7000 leaks. I don understand how to use that tool but I am sure that i am not creating so many variables, jus a few and even those I release.

And just once i got the ERROR " data formatters temporarily unavailable".

Any Idea what i am doing wrong?? F1 :)

PS: my code is all simple stuff, plus i donno what the problem is hence i donno what code to post here? Also i would like to know if i create a NSString* in a function for temp use should i release it at the end of the function?(i do release it) EDIT:

    -(void) loadQuestion
    { 
    strCorrectAnswer = @"";
    int intQuestionNo;
    NSString *strQuestionNo = [[NSString alloc] init];

    // get random question out  the xml file  
NSDictionary *dctQue = [dctQuestions  objectForKey:strQuestionNo];
// blah blah

    // jumble the answers to   be displaed


NSMutableArray *answerJumble = [[NSMutableArray alloc] init];
NSMutableArray *answers =[NSMutableArray arrayWithObjects:[dctQue objectForKey:@"WrongAnswer1"],[dctQue objectForKey:@"WrongAnswer2"],[dctQue objectForKey:@"WrongAnswer3"],[dctQue objectForKey:@"CorrectAnswer"],nil];

 // blah blah

  /*
[strQuestionNo release];
[answers release];
[answerJumble release]; */  

}

B K
  • 1,554
  • 3
  • 19
  • 40
  • Can you show the code for your 'one particular function' where you were seeing crashes? – Carl Norum Feb 16 '10 at 06:12
  • could it be because I use AVAudioPlayer?? i use the following code for music. For EG: NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"sound" ofType:@"caf"]; NSURL *newURL = [[NSURL alloc] initFileURLWithPath: soundFilePath]; iKnow.player = [[AVAudioPlayer alloc] initWithContentsOfURL:newURL error:NULL]; – B K Feb 16 '10 at 06:37
  • the iKnow.player is a variable from appDelegat and i use [iKnow.player play] to play sound when buttons are clicked. likewise i have 2more variable for different sounds. – B K Feb 16 '10 at 06:38
  • The main reason is that you have almost no idea about memory management in Cocoa. (No offense, there’s nothing wrong about it.) There is not much point repeating all that was written about Cocoa memory management here, go read and make the effort to *understand* the links I gave you. You’ll save yourself a lot of trouble in the long run. – zoul Feb 16 '10 at 06:40
  • none taken. i had postponed reading that for a long time now, finally its biting my ass. Thanks for the help will start wit it right away. – B K Feb 16 '10 at 06:45
  • Good decision. Make a few testing programs to play with the rules and make sure you understand them. Even if it took you a whole day, you’ll have the time back in two weeks of coding. – zoul Feb 16 '10 at 06:50
  • hey have u come across that error though?? - "data formatters currently unavailable" – B K Feb 16 '10 at 09:45

2 Answers2

0

You should read something about memory management in Cocoa. See the Mac Developer Center or the tutorial at Cocoa Dev Central. Memory management on iPhone is not hard, it’s a pity to code by trial and error.

zoul
  • 102,279
  • 44
  • 260
  • 354
  • code is a mess. LOL! I hope it luks better now :). thanks fr the help, will start wit the managemt docs rite away. – B K Feb 16 '10 at 06:47
0

well after a bit of digging, the problem was wen the sound file had to be replayed. If i press a button and before the sound file finishes playing if i press again, the sound file was being played just once. Resulting in a memory leak of 3000.

IF i did this twice the app wud crash after a leak of 6425. Hence the ERROR-"data formatters currently not available".(i guess)

B K
  • 1,554
  • 3
  • 19
  • 40