"Reading Notes" ios-object initialization

Source: Internet
Author: User

One, assign the object.

Distribution is the process of a kind of object birth. The best time is to get a piece of memory from the operating system and designate it as the location of the instance variable that holds the object. The result of sending a ALLOC message to a class is to allocate a chunk of memory that is large enough to hold all the instance variables within that class. While The Alloc method also initializes the memory area to 0. Because the various random bugs that are caused by uninitialized memory have plagued many languages, the Alloc method initializes the allocated memory to 0, all of the float type variables are initialized to 0.0, and all pointers are initialized to nil , all the bases belong to us.

Second, initialize the object.

Initializing a piece of memory from the operating system and preparing it for storing objects, the Init method (that is, the method that performs the initialization operation) almost always returns the object they are initializing.

Three, summary.

In cocoa, allocation and initialization are two separate operations: the class method from NSObject Alloc allocates a chunk of memory to the object and zeros it, and the instance method init is used to get an object and make it run.

Reference: "Objective-c Basic Course"

"Reading Notes" ios-object initialization

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.