December 2018
Intermediate to advanced
414 pages
10h 19m
English
Dangling pointers are the opposite of over-retained objects. You can encounter dangling pointers when trying to access a deallocated object. This is best illustrated by the following example:
- (void) doSomething { MyObject *myObject = [[MyObject alloc] init]; // retainCount is +1 [myObject release]; // retain count is 0; object is deallocated // More things happening in this method [myObject myMethod];}
This may not cause a crash all of the time, as myObject could be properly set to nil. When it crashes, you'll face the dreaded NSInvalidArgumentException, which, upon first glance, doesn't make much sense:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[<insert a type here> myMethod]: ...
Read now
Unlock full access