views:

43

answers:

2

Is this good or bad practice?

if (!theConnection && !receivedData) {
        // release the connection, and the data object
        [theConnection release];
        // receivedData is declared as a method instance elsewhere
        [receivedData release];
    }
+5  A: 

Sending any message to nil object has no effect, so you can safely remove that check.

Moreover your code leaks memory in case only 1 of the object is non-nil.

Vladimir
+2  A: 

It's bad practice - just look through Apple's sample code to get a feeling for how it should like.

Use [theConnection release];

or [theConnection release]; theConnection = nil;

and the same for receivedData.

Eiko
as long as `theConnection` and `receivedData` are properties....
Richard J. Ross III
This works with every local variable or property. With (retaining) properties you could just use self.theConnection = nil; although I won't advocate to do this from dealloc.
Eiko