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

Total Post:9

Posted on    November-03-2015 10:17 PM

 iPhone iPhone  Ios  Objective C 

 1 Reply(s)
 512  View(s)
Rate this:

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

   [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:214

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