iPhone - dealloc - Release vs. nil

Viewed 13306

Wondering if someone with experience could possibly explain this a bit more. I have seen examples of...

  [view release];

  view = nil;  

....inside the (void) dealloc.

What is the difference and is one better then the other? What is the best way?

When doing retainCount testing I have personally seen nil drop a count from 3 to 0 for me, but release only drops it from 3 to 2.

5 Answers

@bbullis22 you have seen the restain count drop from 3 to 0 because you set the reference to nil. then you asked for the retaincount of 'nil' which is zero. however, the object that used to be referenced has the same retain count - 1 (due to setting the reference to nil). using release, the reference still references the same object, so that's why you see the retain count drop from 3 to 2 in this situation.

Related