0

I am using UIImagePickerController to take two photos in my app. I am storing those two images in NSData format in two properties declared in AppDelegate which are declared as below.

@property(nonatomic, retain) NSData *dataCheckFront;

@property(nonatomic, retain) NSData *dataCheckBack;

Images I am storing as below:

- (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;

     }
 }

I need the images up-to some point of time in future and I can not avoid storing it somewhere. After the use I am setting those properties to nil like below:

    [((AppDelegate*)[[UIApplication sharedApplication] delegate]) setDataCheckBack:nil];

    [((AppDelegate*)[[UIApplication sharedApplication] delegate]) setDataCheckFront:nil];

But, before setting it to nil itself, the app is terminating because of low memory issue.

How to solve this?

Abizern
  • 146,289
  • 39
  • 203
  • 257
Rashmi Ranjan mallick
  • 6,390
  • 8
  • 42
  • 59
  • 1
    Why don't you save the photos to your Cache or Documents folder first instead of saving them as NSData in the app delegate? – Valent Richie May 29 '13 at 15:22
  • 1
    Intense operations like this should be performed on the background thread instead of the main thread (just a tip to avoid clogging the UI). Could you provide more detail? – Sam Spencer May 29 '13 at 15:26
  • @verbumdei : Thanks a lot for your suggestion. Actually I am new to iOS. So do not know much about it. Please tell me storing in documenta directory will save me rather than in NSData. Again one more thing.. I should save it in documents folder or in temp folder? Please reply me.. – Rashmi Ranjan mallick May 29 '13 at 15:56
  • @RazorSharp : Thanks... Here I wanted to do it in back ground thread. But I could not. I have to send two UIImages in base 64 format to javascript method as a plugin result which is a UIWebView method and it is related to UIKit. Do not know how to do this in another thread. NOTE: This is a phonegap application. – Rashmi Ranjan mallick May 29 '13 at 16:00
  • 1
    http://stackoverflow.com/questions/8209406/ios-5-does-not-allow-to-store-downloaded-data-in-documents-directory – Valent Richie May 29 '13 at 16:02
  • Most likely you have a leak. – Hot Licks May 29 '13 at 16:12
  • @verbumdei : Could you please help me in one thing. How to access the iOS documents directory from a javascript file inside my app? If you have come across this ever then tell me please... – Rashmi Ranjan mallick May 29 '13 at 17:07

1 Answers1

1

You can store those images in document/temp directory itself and whenever required you can fetch the files from document/temp directory, so it won't give you any memory issue. And if you use temp directory then your images won't be there for the next time when you run the app.

Mayur Shrivas
  • 199
  • 1
  • 13