简体   繁体   中英

CGImage causing memory leak

I am creating a cgimage using this code:

UIGraphicsBeginImageContext(CGSizeMake(size*2, size*2));
CGContextRef ctx = UIGraphicsGetCurrentContext();

[[SKColor colorWithWhite:0.8 alpha:1] setFill];
CGContextFillEllipseInRect(ctx, CGRectMake(0, 0, size*2, size*2));

UIImage *textureImage = UIGraphicsGetImageFromCurrentImageContext();
SKTexture *texture = [SKTexture textureWithImage:textureImage];

SKSpriteNode *node = [SKSpriteNode spriteNodeWithTexture:texture];

Clearly it is the source of the problem.

I tried wrapping it in an autorelease block and I tried cfreleasing the cgimageref, but I'm using ARC so those don't really do anything. What is going on??

在此输入图像描述

I think you probably need a call to UIGraphicsEndImageContext to clean things up somewhat.

Also, set your " textureImage " to nil after you create your SKTexture object and see if that helps a bit.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM