First of all, in the ARC era, it is not recommended that you manually manage reference counts
Let’s talk about this problem. In Objective-C, what the code directly controls is not the memory itself, but the reference count of this instance in the memory.
Therefore, after the alloc method initializes jack, jack's reference count is 1. The release method is called, which only decreases the reference count of the jack instance by 1 to 0.
A reference count of 0 does not mean that the instance is destroyed, but it is marked as "the instance can be destroyed".
If your code is written like this
You will find that jack only said the previous sentence once or twice, and then he couldn't say it anymore.
Because the system recycling finds that jack can be recycled, and it takes a little time to reclaim this memory, and during this time, jack said once or twice.
I searched, and my answer is wrong and must be corrected:
The key to being able to print correctly is that the object's memory has not been erased.
The calling mechanism of objective-c is different from that of cpp. I said that cpp has similar content and may mislead you.
When an objC message occurs [obj call], objc_msgSend will be called. For details, see: In-depth analysis of objc_msgSend
When the retainCount in ARC becomes 0, it will notify the system that the object is to be recycled. Sending and processing messages is an asynchronous process, which takes time
Let’s talk about this problem. In Objective-C, what the code directly controls is not the memory itself, but the reference count of this instance in the memory.
Therefore, after the alloc method initializes jack, jack's reference count is 1. The release method is called, which only decreases the reference count of the jack instance by 1 to 0.
A reference count of 0 does not mean that the instance is destroyed, but it is marked as "the instance can be destroyed".
If your code is written like this
You will find that jack only said the previous sentence once or twice, and then he couldn't say it anymore.
Because the system recycling finds that jack can be recycled, and it takes a little time to reclaim this memory, and during this time, jack said once or twice.
I searched, and my answer is wrong and must be corrected:
The key to being able to print correctly is that the object's memory has not been erased.
The calling mechanism of objective-c is different from that of cpp. I said that cpp has similar content and may mislead you.
When an objC message occurs [obj call], objc_msgSend will be called. For details, see: In-depth analysis of objc_msgSend
The release in arc is useless.
When the retainCount in ARC becomes 0, it will notify the system that the object is to be recycled. Sending and processing messages is an asynchronous process, which takes time