如何在-dealloc中正确释放CGMutablePathRef?

Pro*_*ber 3 memory-management core-graphics core-foundation ios

问题:可能是CGMutablePathRef已创建和设置,但可能不是.

我现在做的-dealloc是:

if (path != NULL) {
    CGPathRelease(path);
    path = NULL;
}
Run Code Online (Sandbox Code Playgroud)

它是否正确?

tas*_*oor 8

手册,

void CGPathRelease(CGPathRef path);

此函数等效于CFRelease,但如果path参数为NULL则不会导致错误.

所以不需要NULL检查.