Max Hudson
Max Hudson

Reputation: 10206

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??

enter image description here

Upvotes: 1

Views: 264

Answers (1)

Michael Dautermann
Michael Dautermann

Reputation: 89509

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.

Upvotes: 3

Related Questions