Reputation: 1
I know its a little bit general , but we did EVERY possible thing to find what it is, and we just couldn't .
We have this crash that happens here and there, not always, on this line :
[self.imageOperationQueue addOperationWithBlock:^
{
if(!data)
return ;
UIImage *image=[[UIImage alloc] initWithData:data]; // *** CRASH !
The crash log says :
malloc: *** error for object 0x7fecdb06e5c0: double free
*** set a breakpoint in malloc_error_break to debug
As you can see, and upon our check , data
is not nil when we are creating the image , we have also tried with : [UIImage initWithData:data];
without allocation , but same thing.
EDIT: this is how the code looks like after this row :
if(!data)
return ;
UIImage *image=[[UIImage alloc] initWithData:data];
UIImageView *modelview=[self.allImageView objectAtIndex:index];
float newH=image.size.height* (1.65*modelview.frame.size.width/image.size.width);
CGSize s=CGSizeMake(1.65*modelview.frame.size.width, newH);
if (image)
{
UIGraphicsBeginImageContextWithOptions(s , NO, 0.0);
[image drawInRect:CGRectMake(0, 0, s.width, s.height)];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
Upvotes: 4
Views: 933
Reputation: 299643
Your data
is likely being over-released on another thread. The double-free indicates a memory management imbalance, not a nil-pointer.
If I had to predict the problem, I'd guess you're generating data
from an unsafe pointer, maybe the result of a CoreGraphics call, or a NSData
over malloc'ed memory that gets freed behind your back. Here's how my theory works:
NSData
over unsafe memoryNSData
data
data
at the semicolondata
leads to a free()
The key is that NSData
typically should be the sole owner of its memory; if it's not, then you have to be very careful, especially in multi-threaded operations.
Upvotes: 3