更新:我无法找到导致问题的原因我正在使用beta SDK,并且在使用最终SDK时,问题消失了。我不知道我做错了什么。抱歉。我想删除这个,但不能。被释放的指针未被分配
您好,我有以下错误:
的malloc:*错误对象0x2087000:被释放的指针没有被分配 *设置malloc_error_break断点调试
我不知道是什么对象是。我不知道如何找到它。任何人都可以向我解释如何(以及在哪里)使用malloc_history。我已经在malloc_error_break中设置了一个断点,但我无法找到该地址处的对象。我从nsmutablearray中移除一个对象并手动弹出视图控制器后收到此消息。如果我注释掉[reviewUpload.images removeObject:self.reviewUploadImg]这一行,它不会给我这个错误,但当然这对我没有用处。
- (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]; }
我试图打印出3个地址,但他们都不是被释放但未被分配的地址。
我从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]; }
我不认为我有什么错在这里:ReviewUpload有一个图像阵列可能含有ReviewUploadImage对象。在这些类的实现中,我只有释放方法,我只是释放我必须释放的成员。
@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
是不是有一种简单的方式来获得一个ADRESS Objective-C的对象?
更新: 如果我删除这些行中的任何一个,我不会收到错误。我不知道该说什么这很奇怪。
[reviewUpload.images removeObject: self.reviewUploadImg]; [self.navigationController popViewControllerAnimated:TRUE];
更新:如果在“didFinishPickingMediaWithInfo”中选择的图像为零,则不显示错误。也许它必须按照我创建缩略图的方式做些事情。这是创建它的方法。如果有人有任何想法,请帮助。
-(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; }
你可以把你的代码初始化reviewUploadImg吗?什么是reviewUpload?它是什么样的对象?这将有助于更好地理解您的问题 – 2010-05-05 07:41:01
reviewUploadImg是ReviewUploadImage类,用于存储Review的评论图像(ReviewUpload类)。用户可以为公司或产品撰写评论,并可将图片附加到reviewUpUp.images中存储的评论中。 – 2010-05-05 07:48:06
这个问题为什么这么受欢迎? – 2011-03-25 15:20:36