Runloop in iOS
Usage Scenarios
1. Keep the thread alive, instead of linearly executing the task and exiting
<1> do not turn on Runloop threads
<2> Turn on Runloop threads
(1) Experiment with self to hold child threads
(2) The experiment causes the thread not to end the task to enter the death State]
(3) Event loop mode
(4) Initial attempt to use Runloop
(5) Questions arising from the first experience
Why do ① always put runloop and threads together?
② How do I create a runloop?
③ thread does not turn on Runloop by default, why does our app or the main thread still run without ending?
What are the conditions for ④runloop to function properly?
⑤ besides [Runloop run] and those methods to start runloop?
(6) Initial experience Conclusion
2. Keep the thread alive and let the thread respond to the message when we need it.
3. Have the thread perform a task (timer) on a timed basis
<1> The pit of the first Nstimer encountered
<2> use Nstimer to meet the pits
<3>nstimer caused by Viewcontroller cannot release the problem
<4>performselecter:afterdelay:
4. Monitoring observer to achieve some purpose
About the release of Runloop (the correct wording of the Runloop band Autoreleasepool)
<1> Analysis
<2> need to use the while loop to control Runloop
<3> runloop that do not require a while loop control
<4> about Autoreleasepool in the main thread
Thinking about Runloop switch mode of sub-thread
In this paper, the largest dry, sub-threading simulation of the main thread defaultmode and trackingmode switch, long code warning
Reference documents
<1>runloop
<2>autoreleasepool
Runloop in iOS