更新:我無法找到導致問題的原因我正在使用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