[Reading Notes] iOS-object initialization, Reading Notes ios-

Source: Internet
Author: User

[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

Related Article

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.