After two introductions I would like to have a simple understanding of runloop, at least not ignorant.
In this article I would like to make a simple addition to "cfrunloopobserverref".
Let's talk about it before you add it.
MRC is rarely seen in today's development.
But that's right with the OC object.
Cfrunloopobserverref belongs to CF (Core Foundation)
So we need to release it manually.
The rules are as follows:
Any function created with creat copy retain and other components must be released at the end, i.e. release.
viewcontroller.m//CX runloop Analysis////Created by Ma C on 16/3/29.//Copyright? 2016 Xubaoaichiyu. All rights reserved.//#import "ViewController.h" @interface Viewcontroller () @end @implementation viewcontroller-(void ) Viewdidload {[Super viewdidload];} -(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (uievent *) event{//Add observe/* status monitored Kcfrunlo Opentry = (1UL << 0), kcfrunloopbeforetimers = (1UL << 1), kcfrunloopbeforesources = (1UL << 2), kcfrunloopbeforewaiting = (1UL << 5), kcfrunloopafterwaiting = (1UL << 6), Kcfrunloopexit = (1UL << 7), kcfrunloopallactivities = 0x0fffffffu */cfrunloopobserverref observe = Cfrunloopobservercreatewit Hhandler (Cfallocatorgetdefault (), kcfrunloopallactivities, YES, 0, ^ (cfrunloopobserverref Observer, Cfrunloopactivity activity) {NSLog (@ "Hear runloop--%zd", activity); }); Add Observer Cfrunloopaddobserver (CfrunloopgetcurreNT (), observe, kcfrunloopdefaultmode); CF Memory Management (Core Foundation)/* All objects that are created with functions such as creat copy retain must be released at the end, i.e. release. */Cfrelease (observe);} @end
The above is a simple addition to cfrunloopobserverref.
Here is a brief introduction to Runloop's processing logic.
Runloop processing logic:
1, notify Observer, will enter loop
2, notify Observer, will handle timer
3, notify Observer, will deal with SOURCE0
4, Handling Source0
5, if there is a Source1, jump to the 9th step
6, notify Obesrcer, thread is about to hibernate
7, hibernate, waiting to wake up
8, notify Observer, Line Cheng Gang is awakened
9, processing the message received at wake-up, and then jumping back to 2
10, notify Oberver, will exit loop
An analysis of IOS Runloop three