Home > DeveloperSection > Forums > Is condition is necessary before releasing instance
Eric Martell
Eric Martell

Total Post:9

Points:63
Posted on    November-03-2015 10:17 PM

 iPhone iPhone  Ios  Objective C 
Ratings:


 1 Reply(s)
 310  View(s)
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?



Tarun Kumar

Total Post:213

Points:1635
Supported
Posted on    November-04-2015 10:40 PM

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.


Don't want to miss updates? Please click the below button!

Follow MindStick