search

Home  >  Q&A  >  body text

ios - 谁能说说CGImageRelease和 CGImageRetain的区别?

如题。

比如我创建一个CGImageRef。用完了我要释放,免得内存升高,我应该用哪个?

CGImageRef imageRef = [asset.defaultRepresentation fullScreenImage];

迷茫迷茫2772 days ago637

reply all(4)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 14:27:45

    release is counter -1,, retain is +1
    Need it when you don’t need itrelease

    reply
    0
  • 阿神

    阿神2017-04-17 14:27:45

    1) First check whether you have called CGImageRelease, CGImageCreate or CGImageCreateCopy before using CGImageRetain. .
    2) If not, it will crash. . .
    For asset classes, actively adjusting this does not seem to be useful in reducing memory usage. . .

    reply
    0
  • PHPz

    PHPz2017-04-17 14:27:45

    Although there is ARC now, you still need to understand MRC

    reply
    0
  • 迷茫

    迷茫2017-04-17 14:27:45

    If you need to release memory, of course call CGImageRelease. CGImageRelease sets the reference count to -1. When the reference count reaches 0, the system will release and reclaim the memory. The counterpart to this is retain +1. Although ARC is used more now, the author still needs to understand and learn about memory management.

    reply
    0
  • Cancelreply