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. 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
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.
edit: It seems the crash is actually happening when I try to load this array into a table. Would it be better to use another format to store the image? like NSData? Here's my code for the table.
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.
Code:
- (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: It seems the crash is actually happening when I try to load this array into a table. Would it be better to use another format to store the image? like NSData? Here's my code for the table.
Code:
- (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;
return cell;
}