NSString initialization and memory management, nsstring Initialization

Source: Internet
Author: User

NSString initialization and memory management, nsstring Initialization

1. NSString three initialization Methods

A. Direct Value assignment: NSString * str = @ "a string", which uses constant memory.

B. Use the class method: NSString * str = [NSString stringWithString: @ "a string"];

NSString * str = [NSString stringWithFormat: @ "age is % I, height is % f", 20,180];

C. Use the instance method: NSString * str = [[NSString alloc] initWithString: @ "a string"];

NSString * str [[NSString alloc] initWithFormat: @ "age is % I, height is % f", 20,180];

 

2. NSString Memory Management

Use Xcode 6.1.1 to test and create a new NSString. We found that the initWithString and stringWithString that were not warned in Xcode4.6 will both be reported as follows. Du Niang found that there is an answer, the reason is that the new version of Xcode has been optimized, which means this writing method is redundant. We recommend that you write it in a format like 'nsstring * str =, in this way, the memory of str will be opened directly from the constant memory area.

Reference: http://www.cnblogs.com/celestial/archive/2012/10/10/2719169.html

Http://www.cnblogs.com/hellocby/archive/2012/08/23/2652201.html

 

To be supplemented...

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.