ARC-do not send messages to released objects. arc-release sends messages.
1. Write the following code in AppDelegate. m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. NSObject *object=[[NSObject alloc]init]; NSLog(@"%ld",[object retainCount]); [object release]; NSLog(@"%ld",[object retainCount]); return YES;}
2. Run the command to obtain the following output.
21:44:57. 889 ARC do not send messages to released objects [2245: 90589] 12015-07-14 21:44:57. 890 ARC do not send messages to released objects [2245: 90589] 1
3. Result Analysis.
1. The memory collection method for reference counting is "only mark, not erase relevant data ". It is a bit like deleting data on a mobile hard disk, but not deleting the data.
2. In the above Code, after the obect object is released, the referenced object is not always 1, and sometimes the program crashes. When the memory occupied by the object is reused, the program crashes.
3. "Do not send messages to released objects ". In this example, a retainCount message is sent to a released object.
4. When an object is recycled through the release memory, any message is sent to the object, regardless of whether the output result is correct or incorrect. Even as expected, it happened.
References:
Advanced iOS development-Tang Qiao