IS CONDITION IS NECESSARY BEFORE RELEASING INSTANCE

Eric Martell

Total Post:9

Points:63
Posted by  Eric Martell
 568  View(s)
Ratings:
Rate this:

Whenever I release any instance that could exists or not, I am using this code:

if(myObject!=nil)
{
   [myObject release];
}

but I have a confusion, sending a message to nil is not a problem;
I want to know, is that condition necessary?

  1. Tarun Kumar

    Post:214

    Points:1642
    Re: Is condition is necessary before releasing instance

    There is no need to check nil, because by default Objective C checks for nil,
    So there is no need to check it twice.

    [myObject release];
    myObject = nil;

    but, you can do some extra code with that object here, before releasing the object.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!