Question

My problem is when I use the camera UIImagePicker and the phone is low on memory. It throws a memory warning and unloads the view and then reloads.

I know this is a very common problem and many questions are already in SO. I'm not going into this.

- (void)viewDidLoad
{
    [super viewDidLoad];

    MyPersonClass *persons = [[MyPersonClass alloc] init];   
    persons.images = [NSMutableDictionary dictionaryWithCapacity:4];
....
...
}    

My issue is the my view controller has four buttons and UIImageViews and when I tap each, they open the camera and image clicked is shown back in the UIImageViews and these images are also stored in the persons.images NSMutable Dictionary.

enter image description here

Sometimes it throws the popular error of memory warning and Unloads the view and this removes all the images in the UIImageView which were taken before the memory warning and I lose everything in persons.iamges I just want to be able to retrieve this data back. I don't know where to store it (I don't want to use CoreData for this).

Was it helpful?

Solution

You can maintain instance variables for storing image when viewDidUnload gets called. set a flag in viewDidUnload and then store all the images of your Imageviews. And in viewDidLoad check the flag that if viewDidUnload was called then assign the saved images to your ImageView.

OTHER TIPS

You can save your MutableDictionary as a plist in the sandbox's application like that

[yourMutableDictionary writeToFile:pathToSave atomically:YES];

And then, get your NSMutableDictionary by this way

NSMutableDictionary *containOfPlist = [NSMutableDictionary arrayWithContentsOfFile:pathToYourPlist];

Hope this is what you want.

please use the NSCache for storing the images with KeyValue pair. On the memory warning write the NSCache object to file and clear all objects from NScache object on low memory warning call back. on loading application again rad the NSCAche from that file.

so i that manner you can save the data and can use it back.

another alternate option is to take NSDictnaory and store it via using NSArchiver class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top