Hello i have the following error:
malloc: * error for object 0x2087000: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug
I have no idea what object that is. I don't know how to find it. Can anybody explain to me how (and where) to use malloc_history. I have set a breakpoint in malloc_error_break but i couldn't find out what object is at that address. I receive this after removing an object from an nsmutablearray and popping a view controller manually. If I comment out the line [reviewUpload.images removeObject: self.reviewUploadImg] it doesn't give me the error but of course it's not useful for me like that.
- (void) removeImage { debugLog(@"reviewUploadImg %@", self.reviewUploadImg); debugLog(@"reviewUpload %@", self.reviewUpload); debugLog(@"reviewUploadImg thumb %@", self.reviewUploadImg.thumb); [reviewUpload.images removeObject: self.reviewUploadImg]; [self.navigationController popViewControllerAnimated:TRUE]; }
I tried to print out 3 adressess but neither of them is the address that was being freed but not allocated.
I add the image from an UIImagePickerController.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *pickedImage = (UIImage *)[info objectForKey: UIImagePickerControllerEditedImage]; if (!pickedImage) pickedImage = (UIImage *)[info objectForKey: UIImagePickerControllerOriginalImage]; if (!reviewUpload.images) reviewUpload.images = [[NSMutableArray alloc] initWithCapacity: 5]; //UIImage *thumbImage = [pickedImage copyResizedImage: CGSizeMake(120, 120)]; UIImage *thumbImage = [pickedImage copyResizedImage:CGSizeMake(120, 120) withPaddingColor: [UIColor lightGrayColor]]; ReviewUploadImage *rui = [[ReviewUploadImage alloc] init]; rui.thumb = thumbImage; [thumbImage release]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat: @"yyyyMMddHHmmssSS"]; NSDate *date = [NSDate date]; NSString *tmpFileName = [dateFormatter stringFromDate: date]; [dateFormatter release]; NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent: tmpFileName]; NSData *imageData = [[NSData alloc] initWithData: UIImageJPEGRepresentation(pickedImage, 0.90)]; [imageData writeToFile: path atomically: TRUE]; [imageData release]; rui.path = path; [reviewUpload.images addObject: rui]; debugLog(@"rui rc %i", rui.retainCount); [rui release]; [self dismissModalViewControllerAnimated:TRUE]; }
I don't think i have anything wrong here: ReviewUpload has an images array which may contain ReviewUploadImage objects. In the implementation of these classes i have only the release method, I just release the members i have to release.
@interface ReviewUpload : NSObject { NSString *title; NSString *tags; NSString *text; NSInteger rating; NSMutableArray *images; NSInteger idCompany; NSInteger idProduct; } @property(nonatomic, copy) NSString *title; @property(nonatomic, copy) NSString *tags; @property(nonatomic, copy) NSString *text; @property(nonatomic, assign) NSInteger rating; @property(nonatomic, retain) NSMutableArray *images; @property(nonatomic, assign) NSInteger idCompany; @property(nonatomic, assign) NSInteger idProduct; @end
@interface ReviewUploadImage : NSObject { UIImage *thumb; NSString *path; } @property(nonatomic, retain) UIImage *thumb; @property(nonatomic, copy) NSString *path; @end
Isn't there an easy way to get the objective-c object from an adress?!
UPDATE: If i remove either of these lines i don't get the error. I don't know what to say this is really weird.
[reviewUpload.images removeObject: self.reviewUploadImg]; [self.navigationController popViewControllerAnimated:TRUE];
UPDATE: if the image selected in "didFinishPickingMediaWithInfo" is nil no error is displayed. Maybe it has to do something with the way i create the thumbnail. Here is the method that creates it. If anybody has any idea please help.
-(UIImage *) copyResizedImage:(CGSize) thumbSize withPaddingColor: (UIColor *) bgColor { CGFloat resizedProp = thumbSize.width / thumbSize.height; CGFloat imageProp = self.size.width / self.size.height; CGSize newSize; CGFloat factor; if (imageProp > resizedProp) //image is wider factor = thumbSize.width / self.size.width; else factor = thumbSize.height / self.size.height; newSize.width = self.size.width * factor; newSize.height = self.size.height * factor; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; UIImage *resizedImage; UIGraphicsBeginImageContext(thumbSize); CGContextRef drwContextRef = UIGraphicsGetCurrentContext(); CGContextSetFillColorWithColor(drwContextRef, bgColor.CGColor); CGContextFillRect(drwContextRef, CGRectMake(0, 0, thumbSize.width, thumbSize.height)); CGRect imageRect = CGRectMake( (thumbSize.width - newSize.width) / 2.0, (thumbSize.height - newSize.height) /2.0, newSize.width, newSize.height); [self drawInRect:imageRect]; resizedImage = UIGraphicsGetImageFromCurrentImageContext(); // this is autoreleased and i dont need it UIGraphicsEndImageContext(); [resizedImage retain]; [pool release]; return resizedImage; }