Deallocated instance and nil object in objective-c-Collection of common programming errors
Coming from a java background, where everything goes under null pointer exception, I found some difficulties in understanding the difference between nil and deallocated instance in objective-c.
In objective-c it is known that sending a message to a nil object is not sorting any effect to the program flow.
However, sending a message to a deallocated object result in message to deallocated instance error.
In my ideal world a deallocated instance is ‘nil’, but obviously is not.
The precise question are:
- what happens to the object when it is deallocated ?
- If the object is deallocated, shouldn’t it be freed, and then become nil ?