views:

489

answers:

1

Hello wonderful people of stackoverflow!

I have a problem.

I am working on an app that will take multiple photos and each time it will enlarge them, show a preview, save them, and then load the UIImagePickerController again.

But after taking about 5 to 6 pictures it dies.

I think that it is dying because I have a UIImageView that I set and after so many pictures the UIImage that I set it with is no longer referencing anything.

I think that the culprit is somewhere in here...

Is there something that I am doing wrong?

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    [backgroundImage setImage: [[UIImage alloc] initWithCGImage:[[info objectForKey:UIImagePickerControllerOriginalImage] CGImage]]];
    [backgroundImage setTransform:CGAffineTransformRotate(CGAffineTransformMakeScale(zoom/3, zoom/3), 1.570796327)];

    UIGraphicsBeginImageContext([backgroundView bounds].size);
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    CGContextFillRect(ctx, [backgroundView bounds]);
    [backgroundView.layer renderInContext:ctx];
    UIImage* screenImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    UIImageWriteToSavedPhotosAlbum(screenImage, self, @selector(ImageDidSave:didFinishSavingWithError:contextInfo:), nil);

    [self dismissModalViewControllerAnimated:YES];
}

backgroundImage is the one that eventually tries to use an image that is no longer referencing anything.

Let me know how I can clarify.

Thank you very much everyone who stayed with me this far!

+1  A: 

This is a guess, but I bet you're running out of memory and being killed. Try autoreleasing the image you send to the background in this line:

[backgroundImage setImage: [[[UIImage alloc] initWithCGImage:[[info objectForKey:UIImagePickerControllerOriginalImage] CGImage]] autorelease]];
kubi
THANK YOU!I honestly didn't think your solution was going to fix this because I have tried ALL KINDS of releasing this and that and so on.But somehow I managed to miss trying this.Thank you again!You rock!Best wishes!