Nsuserdefaults and memory

Source: Internet
Author: User

Nsuserdefaults is designed to store the configuration information of devices and applications. It returns the default and most common instance objects through a factory method. This object stores user configuration information in the system. developers can modify the existing information through this instance object, or create new configuration items as needed.

Nsuserdefaults organizes configuration information in the form of a dictionary. dictionary items include strings or arrays. In addition, basic formats such as numbers are supported. In a word, it is a basic dictionary of small data. The operation method is almost the same as the nsdictionary operation method. In addition, you can obtain the return value of the specified type by specifying the return type.

The above is the opening remarks. Note the following:


All data of nsuserdefaults is stored in the memory.Therefore, the operation is fast, and an archive method is also provided: +
(Void) synchronize. The custom configuration item (the last key in 2: alkdjfkladsjfmm) is archived in the/library/preferences/[app_bundle_identifier]. plist file of the corresponding application directory in plist format. After the instance object is re-initialized, the framework combines the User-Defined configuration with the system configuration to obtain complete data.


That is to say
When you load nsuserdefaults once, it will load all the data into the memory, and then it will be resident memory.

Think again,
You have been tossing him for a long time, just to save a little memory, which knows that loading nsuserdefaults will waste some memory, once you save all the large data to nsuserdefaults, this result may be disastrous!


Therefore, it is best to use nsuserdefaults to store a large amount of data.
Better than coredata




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.