0

I am creating a quiz app in iPhone.
So that i have so many labels and buttons in use at a time.
If i release them right after one question then application stops.
If i am not doing that and releasing them at dealloc function then it shows memory warning and app crashes. I am using this Code

received memory warning. level 1

If i set around 20 questions then application is not crashing but if i add more questions then it crashes..
I think it is allocating memory and not releasing right after one question.

Please help me out this:(

Edited :
I am using this code after selecting answer

-(void)checkAnswer:(int)theAnswerValue
{   
[AVback stop];
[scrollview scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:NO]; 
[Challengetext setHidden:YES];
[theScore setHidden:YES];
[theQuestion setHidden:NO];
[Question setHidden:YES];  
if(rightAnswer == theAnswerValue)
{
    NSString *AVpath = [[NSBundle mainBundle] pathForResource:@"Winner_1" ofType:@"m4a"];
    AVAudioPlayer *AVbtn1 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:AVpath] error:NULL];


    [img1 setHidden:NO];
    [img2 setHidden:YES];
    [theQuestion setFont:[UIFont fontWithName:@"Futura" size:30]];
    theQuestion.textColor = [UIColor purpleColor];
    theQuestion.text = @"\n\nCorrect Answer!!";
    [rightans setHidden:NO];
    [Description setHidden:NO];
    [ContainerView setHidden:NO];
    myScore = myScore + 50;
}
else
{

    NSString *AVpath = [[NSBundle mainBundle] pathForResource:@"incorrect2" ofType:@"m4a"];
    AVAudioPlayer *AVbtn1 = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:AVpath] error:NULL];
    QuizAppUniversalAppDelegate *appDelegate = (QuizAppUniversalAppDelegate *) [[UIApplication sharedApplication] delegate];
    if(appDelegate.soundIndicator == 0){
        [AVbtn1 play];

    }
    else{
        [AVback stop];
        [AVstart stop];
        [AVbtn1 stop];
    }

    [img2 setHidden:NO];
    [img1 setHidden:YES];
    [theQuestion setFont:[UIFont fontWithName:@"Futura" size:30]];
    theQuestion.textColor = [UIColor redColor];
    theQuestion.text = @"\nIncorrect Answer!!\nRight answer is : \n ";
    [rightans setHidden:NO]; 
    [Description setHidden:NO];
    [ContainerView setHidden:NO];
    myScore = myScore ;

}

Thanks.. Any help will be appreciated.. !!

Community
  • 1
  • 1
iUser
  • 1,075
  • 3
  • 20
  • 49
  • could you show how you create the labels and buttons? what do you do when one question is answered? – sergio Aug 17 '11 at 11:25
  • for buttons and labels my code is on above link and after answering the question the result , i mean answer CORRECt or INCORRECT is displaying. Let me edit code for that.. so you have some idea.. – iUser Aug 17 '11 at 11:33
  • Thanks. When the answer is correct and you move to the next question, how do you do that? You push a new view controller on a navigation controller? replace the current view? – sergio Aug 17 '11 at 11:40
  • Memory warning would not cause app crash. The crash is probably because of something getting deallocated twice, e.g. you released something you did not retain and then on dealloc system tried to release it. – jamihash Aug 17 '11 at 11:44
  • At that time i set NEXT button to [nextbtn setHidden:NO]; When i tap this button it goes to [self askQuestion]; And code for that is on above link.. Thanks.. – iUser Aug 17 '11 at 11:46
  • @ jamihash : Thanks..!! i checked it and corrected it.. but still app is crashes after running 11 question four times.. in instruments control it shows that at that time i am allocating more than 10 mb.. Do u think it would be problem for app crash?? – iUser Aug 17 '11 at 12:16

1 Answers1

0

You don't appear to be releasing your avBtn1 object anywhere, and you are allocating a new one every time checkAnswer is called. Is that dealt with somewhere else in the code?

jrturton
  • 118,105
  • 32
  • 252
  • 268
  • I tried It.. If i release avBtn1 here then i can't get background music for that.. Do you think App crashes for not releasing avBtn1?? – iUser Aug 17 '11 at 12:24