views:

7

answers:

0

i searched over internet but did not get suitable solution of this error Here I'm posting code that i made.

My application captures near 200 questions form sqlite db and then creates screen shot of them for slideshow. Application crashes when app captures near 86-87 questions via UIGraphicsBeginImageContext() and fills them into a NSMutableArray

Here is the code of .m file-

aryImages = [[NSMutableArray alloc]initWithCapacity:[aryAllQues count]];
    aryQuestionIDsInOrder = [[NSMutableArray alloc]initWithCapacity:[aryAllQues count]];
    aryQuestionsInOrder = [[NSMutableArray alloc]initWithCapacity:[aryAllQues count]];
//aryAllQues is a collection of 200 questions in a NSMutableArray

    for (int i = 0; i < [aryAllQues count]; i++)
    {
        int indexforCollection = [[collectNumbers objectAtIndex:i] intValue];
        NSString *sentence = [[NSString alloc] initWithString:[aryAllQues objectAtIndex:indexforCollection]];

        if(i == [aryAllQues count] -1)
            imgKeepThink.hidden = YES;

        CGRect txtQuesRectP1 = CGRectMake(30, 100, 420, 60);
        lblQues = [activityViewController createLabelControl:sentence frame:txtQuesRectP1 txtAlignment:UITextAlignmentCenter numberoflines:2 linebreakmode:UILineBreakModeWordWrap fontwithname:@"ArialRoundedMTBold" fontsize:23 txtcolor:[UIColor colorWithRed:150.0/255 green:150.0/255 blue:150.0/255 alpha:1.0] backgroundcolor:[UIColor clearColor]];
        [self.view addSubview:lblQues];    

        questionid = [aryQuesid objectAtIndex:i];

        CGRect contextRect  = CGRectMake(0, 0, 480, 320);
        UIGraphicsBeginImageContext(contextRect.size);
        [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];

        [aryImages addObject:UIGraphicsGetImageFromCurrentImageContext()];
        UIGraphicsEndImageContext();
        NSLog(@"Captured Image %d", i);
        [aryQuestionIDsInOrder addObject:questionid];
        [aryQuestionsInOrder addObject:sentence];

        lblQues.hidden = YES;
        [lblQues release];
    }
    NSLog(@"######### Captured #########\n Images- %d, \nQuestionId- %d, \ntotal ques- %d", [aryImages count], [aryQuestionIDsInOrder count], [aryQuestionsInOrder count]);

+ (UILabel *)createLabelControl: (NSString *)title frame:(CGRect)frame txtAlignment:(UITextAlignment )txtAlignment numberoflines:(NSInteger)numberoflines linebreakmode:(UILineBreakMode)linebreakmode fontwithname:(NSString *)fontwithname fontsize:(NSInteger)fontsize txtcolor:(UIColor *)txtcolor backgroundcolor:(UIColor *)backgroundcolor {
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.text = title;
    label.textAlignment = txtAlignment;
    label.numberOfLines = numberoflines;
    label.lineBreakMode = linebreakmode;
    [label setFont:[UIFont fontWithName:fontwithname size:fontsize]];
    label.textColor = txtcolor;
    label.backgroundColor = backgroundcolor;
    return label;
}

Everytime it fills question into the UILabel- lblQues then app captures screen and stores it into NSMUtableArray aryImages

Here I'm Pasting variable declaration also of .h file-

@interface activityViewController : UIViewController
{
    UIActivityIndicatorView *activityIndicator;
    NSMutableArray *aryAllQues;
}

NSMutableArray *aryImages, *aryQuestionIDsInOrder, *aryQuestionsInOrder; are declared in a separate header file sothat i can use them as global variables.

I know memory leaking is causing due to 480x320 screenshot but it is important for me to create screen shot of 480x320 only. My next step will be to open a new view controller with aryImages and will play a slideshow of questions.

Please guide me, I'm frustrated and have killed my whole day