i’m a bit confused, when we release a pointer or use nil to the pointer, it releases the memory. But what about the pointer itself? it points to an object that does not exist anymore, so is the pointer automatically removed? is it implied that dealloc releases both the memory and the pointer itself?
Thanks
The pointer is a local variable representing an address in memory, not an object. There’s nothing to release.
For example:
You now have 2 local variables in the stack, one of type
intand the other of typepointer to NSSomething. You also have a newNSSomethinginstance in the heap. If you simplyreturnnow, youriandobjectvariables will go out of scope and disappear, but theNSSomethinginstance in the heap will live on forever. To avoid that, you mustrelease(orautorelease) it before youreturnfrom the function.