In my app I have an array of objects, called annotatedImages. One of the fields of this object is UIImage *image. I also have an imagePickerController using the camera. When the user takes an image it then creates a new annotatedImage and sets the image of that object to the cameras picture and adds it to the array. This works fine up till about the forth picture, when I get a "Received memory warning. Level=2" which then results in the program crashing and I receive this error
Program received signal: “0”. Data Formatters temporarily unavailable, will re-try after a 'continue'. (Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib") kill
I'm guessing that the iphones memory is being overloaded somehow. Do you have any suggestions on how to fix this? Here's the code where the object is being added to the array in the imagePickerController. I should also mention that I tried releasing the image, but I got a EXC_BAD_ACCESS error, which I'm guessing is due to the newly created objects image pointing to that image. Is there a way to cache the images in the array? or reduce the amount of memory they take up?
- (void) imagePickerController: (UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *image;
NSURL *mediaUrl;
mediaUrl = (NSURL *)[info valueForKey:UIImagePickerControllerMediaURL];
if(mediaUrl == nil){
image = (UIImage *) [info valueForKey:UIImagePickerControllerEditedImage];
if(image == nil){
image = (UIImage *) [info valueForKey:UIImagePickerControllerOriginalImage];
[image retain];
imageView.image = image;
AnnotatedImage *a = [[AnnotatedImage alloc] initWithName:@"Picture" description:@"mmmm"];
[a setImage: image];
[images addObject:a];
}
else{
imageView.image = image;
}
}
else {
//<#statements#>
}
[picker dismissModalViewControllerAnimated:YES];
edit: I think the problem is actually in the tableview that loads the images. It doesn't crash at all when I remove the line that sets the cells imageview to the objects image.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//create cell
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"test"];
if(cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"test"] autorelease];
}
a = [globalMainVC.images objectAtIndex:indexPath.row];
//fill cell with content
cell.textLabel.text = a.name;
cell.imageView.image = a.image; // If I remove this line, there's no crashes
return cell;
}