IOS multi-threaded automatic release Chichong meet question code

Source: Internet
Author: User

Synchronization: Code executes sequentially, one person performs multiple tasks, and is executed in turn. A person performs only one task at a time

Async: Multiple tasks can be performed at the same time

Process: Refers to the application running in the system, each process is independent and has a separate and secure running space

Threads: A process can have multiple threads, but only one main thread. The task of the process is done within the thread.

Process, the relationship between threads and multithreading?

Process = Company Thread = Employee Multi-Threading = Boss

Multithreading can solve the problem of program blocking, but also can improve the efficiency of program execution

Automatically release Chichong meeting question code

For (int i = 0; i < 100000; ++i) {

nsstring *str = @ "Hello World";

str = [str Stringbyappendingformat:@ "-%d", I]; string concatenation

str = [str uppercasestring]; Replace a string with uppercase

}

What happens if the number of loops is too large? How to solve it?

there will be a memory overflow, Create a large number of temporary objects inside the loop without being released

Each loop will be the last object created.

For (int i = 0; i < 100000; ++i) {

@autoreleasepool {

nsstring *str = @ "Hello World";

str = [str stringbyappendingformat:@ "-%d", I];

str = [str uppercasestring];

}

}

IOS multi-threaded automatic release Chichong meet question code

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.