Memory leakage occurs when the iPhone adds this thread!

Source: Internet
Author: User

1: original from: http://www.cocoachina.com/bbs/read.php? Tid = 42551

 

 

I assign values to many attributes in the dootherfunc function called by the subthread. These attributes are defined as @ property (nonatomic, retain )."Nonatomic multithreading related ~ Writing without multithreading can improve efficiency"Now I have multiple threads, right? Can't we improve efficiency? The relationship between attributes defined as nonatomic and multithreading is not too clear. Which of the following experts will explain the relationship! Thank you! 

 

the default attribute we define is atomic, it means that you need to add a lock operation before accessing these attributes, and then add the unlock operation after the access, so as to avoid some unknown problems caused by simultaneous access in different threads.
if this is not added, for example, two subthreads run simultaneously, if you modify the value of an object in the first thread or release the object, the second thread may get an incorrect value, or the Program crash is generated because the object is being used but is dropped by the first thread relase.
the lock and unlock may cause system consumption, if we determine that we will not use the attributes in different threads at the same time, we can define them as nonatomic to reduce system consumption. If we may access them in different threads, use atomic, or do nothing (because atomic is the default ).

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.