开发者

Do I have a memory management problem in here?

开发者 https://www.devze.com 2022-12-22 10:21 出处:网络
Something must be wrong with this code right here: + (UIImage*)captureView:(UIView *)theView { UIGraphicsBeginImageContext(theView.frame.size);

Something must be wrong with this code right here:

+ (UIImage*)captureView:(UIView *)theView {
    UIGraphicsBeginImageContext(theView.frame.size);
    [theView.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}

When I use that, Xcode throws me this error message:

开发者_Go百科

malloc: * error for object 0x103f000: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug

I can't see any memory management errors there. Does anyone else?


I had the same warning. But, it does not occur in 3.1 or above.


Don't see. Set NSZombie enabled in the build to track it down.

It might be related to returning an autoreleased UIImage from a class method which will probably be inside of a temporary autorelease pool. The image might be being destroyed by the draining of that pool. To test, move the method to an instance method and see if the problem goes away.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号