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 Codereceived 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];
[Des开发者_JAVA技巧cription setHidden:NO];
[ContainerView setHidden:NO];
myScore = myScore ;
}
Thanks.. Any help will be appreciated.. !!
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?
精彩评论