在释放对象之前检查nil

She*_*lam 0 memory iphone cocoa-touch objective-c

这是好事还是坏事?

if (!theConnection && !receivedData) {
        // release the connection, and the data object
        [theConnection release];
        // receivedData is declared as a method instance elsewhere
        [receivedData release];
    }
Run Code Online (Sandbox Code Playgroud)

Vla*_*mir 5

将任何消息发送到nil对象都没有效果,因此您可以安全地删除该检查.

此外,如果对象中只有一个是非零的,则代码会泄漏内存.