[Reading Notes] iOS-object initialization, Reading Notes ios-
1. Allocate objects.
Allocation is the process of the birth of an object. The best time is to get a piece of memory from the operating system and specify it as the location of the instance variable that stores the object. The result of sending an alloc message to a class is to allocate a large enough memory for the class to store all the instance variables in the class. At the same time, the alloc method also initializes all the memory areas to 0. various random bugs caused by uninitialized memory have plagued many languages, while the alloc method initializes allocated memory to 0, and all float type variables are initialized to 0.0, all pointers are initialized to nil, and all the bases belong to us.
2. initialize the object.
The initialization gets a piece of memory from the operating system and prepares to store objects. The init method (that is, the method for executing the initialization operation) almost always returns the objects they are initializing.
Iii. Summary.
In Cocoa, allocation and initialization are two separate operations: the class method alloc from NSObject allocates a memory area for the object and clears it, the instance method init is used to obtain an object and run it.
References: Objective-C basic tutorial