When we call alloc with a Class, Whether the object's reference count will be 1.
For example:
NSObject *obj = [NSObject alloc];
After this line of code is executed, the reference count of the object is 0 or 1?
I read the alloc source code, But did not find the alloc method will have any action on the object's reference count,At this point the object of the reference count is still 0?
if 0, then the object will be destroyed, but if not 0, how it is achieved,
I hope someone can help me answer the hearts of confusion, thank you!
alloc creates the object with a reference count of 1. It doesn't create it with a reference count of 0 and increases the reference count. First, that would be inefficient (one extra retain call for each object created), and second, it wouldn't work, because once an object has a reference count of 0, Objective-C will absolutely definitely deallocate the object; there is no way to stop the deallocation, and one side effect of that is that you cannot increase or decrease the reference count of an object with zero reference count.