iPhone development: pointer being freed was not allocated

前端 未结 7 1823
粉色の甜心
粉色の甜心 2020-12-02 12:33

i got this message from the debugger:

Pixture(1257,0xa0610500) malloc: *** error for object 0x21a8000: pointer being freed was not allocated
*** set a breakpo         


        
7条回答
  •  攒了一身酷
    2020-12-02 13:06

    I had the same issue with the following code.

    -(void)adjustImageToImageView:(UIImage*)img{
    
    float numPixels = 100;
    float radius = 5;
    UIGraphicsBeginImageContext(CGSizeMake(numPixels, numPixels));
    CGContextRef c = UIGraphicsGetCurrentContext();
    
    CGContextBeginPath(c);
    CGContextMoveToPoint  (c, numPixels, numPixels/2);
    CGContextAddArcToPoint(c, numPixels, numPixels, numPixels/2, numPixels,   radius);
    CGContextAddArcToPoint(c, 0,         numPixels, 0,           numPixels/2, radius);
    CGContextAddArcToPoint(c, 0,         0,         numPixels/2, 0,           radius);
    CGContextAddArcToPoint(c, numPixels, 0,         numPixels,   numPixels/2, radius);
    CGContextClosePath(c);
    
    CGContextClip(c);
    
    [img drawAtPoint:CGPointZero];
    UIImage *converted = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    self.imageView.image = converted;   }
    

    I took the function from the open source Twitterfon app.

    When I was trying to fix the issue, I tried changing the last line to

    self.imageView.image = [converted retain]
    

    And that stopped the error messages in the console. I'm going to check this in Leaks soon to see whats happening.

提交回复
热议问题