我正在使用 UIImagePickerController 在我的应用程序中拍摄两张照片。我将这两个图像以 NSData 格式存储在 AppDelegate 中声明的两个属性中,声明如下。
@property(nonatomic, retain) NSData *dataCheckFront;
@property(nonatomic, retain) NSData *dataCheckBack;
我存储的图像如下:
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
NSLog(@"camera took photo...");
[self cleanUpOverlayAndCameraView];
if (iCheckSide==FRONT) {
NSData *dataImage= [[NSData alloc] initWithData:UIImageJPEGRepresentation([info objectForKey:UIImagePickerControllerOriginalImage], 1.0)];
((AppDelegate*)[[UIApplication sharedApplication] delegate]).dataCheckFront= dataImage;
[dataImage release];
dataImage= nil;
}
else {
NSData *dataImage= [[NSData alloc] initWithData:UIImageJPEGRepresentation([info objectForKey:UIImagePickerControllerOriginalImage], 1.0)];
((AppDelegate*)[[UIApplication sharedApplication] delegate]).dataCheckBack= dataImage;
[dataImage release];
dataImage= nil;
}
}
我需要这些图像直到将来某个时间点,我无法避免将它存储在某个地方。使用后,我将这些属性设置为 nil,如下所示:
[((AppDelegate*)[[UIApplication sharedApplication] delegate]) setDataCheckBack:nil];
[((AppDelegate*)[[UIApplication sharedApplication] delegate]) setDataCheckFront:nil];
但是,在将其设置为 nil 之前,应用程序由于内存不足问题而终止。
如何解决这个问题?