Memory management in Objective-C and setting pointers to nil

garbage-collection, memory-management, objective-c

Solution

No, it won't, because the deallocation does not have the power to change the pointer. It could only do this is you passed a pointer to the pointer.

If you want to ensure it's set to nil, you have to do it yourself.

Some consider this good practice, some consider it a waste of time since your code should be structured to not use pointers after deallocation (until reallocated).

I actually lean towards the latter camp but I can see why people want to protect themselves from accessing freed memory (programming defensively is rarely a bad idea).

Problem

Will the pointer to an object go to `nil` when its count goes to 0 or when dealloc is called? Why or why not?

Original source