The difference between new and alloc/init in iOS development, iosnewallocinit

Source: Internet
Author: User

The difference between new and alloc/init in iOS development, iosnewallocinit

[ClassName new] is basically equivalent to [[className alloc] init];

The difference is that zone is used when alloc allocates memory.

What is this zone?

When allocating memory to objects, it allocates the associated objects to an adjacent memory area, so as to consume a small amount of money during calls and increase the processing speed of the program;

If new is used, the initialization method is fixed and only init can be called.

What if you want to call initXXX? No! It is said that the initial design fully draws on the Smalltalk syntax.

The new and alloc/init functions are almost the same, allocating memory and completing initialization.

The difference is that the new method can only use the default init method to complete initialization,

You can use other custom initialization methods using alloc.

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.