【问题标题】:CGImage causing memory leakCGImage 导致内存泄漏
【发布时间】:2014-06-07 16:45:16
【问题描述】:

我正在使用此代码创建一个 cgimage:

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];

显然这是问题的根源。

我尝试将它包装在一个自动释放块中,并尝试释放 cgimageref,但我使用的是 ARC,所以它们并没有真正做任何事情。怎么回事??

【问题讨论】:

    标签: ios objective-c xcode automatic-ref-counting instruments


    【解决方案1】:

    我认为您可能需要致电 UIGraphicsEndImageContext 进行一些清理工作。

    另外,在创建 SKTexture 对象后将“textureImage”设置为 nil,看看是否有帮助。

    【讨论】:

      猜你喜欢
      • 2023-03-24
      • 2015-07-06
      • 2013-11-20
      • 2011-10-28
      • 2016-01-18
      • 2012-12-13
      • 1970-01-01
      • 2011-01-08
      • 2011-02-01
      相关资源
      最近更新 更多