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.
Arc has rarely been seen in the current 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//A brief analysis of CX Runloop////Created by Ma C on 16/3/29.//copyright©2016 year Xubaoaichiyu. All rights reserved.//#import "ViewController.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload];}-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event{ //Add observe /*Monitored status Kcfrunloopentry = (1UL << 0), kcfrunloopbeforetimers = (1UL << 1), Kcfrunloopbeforesou RCEs = (1UL << 2), kcfrunloopbeforewaiting = (1UL << 5), kcfrunloopafterwaiting = (1UL << 6), Kcfrunloopexit = (1UL << 7), kcfrunloopallactivities = 0x0fffffffu*/Cfrunloopobserverref Observe= Cfrunloopobservercreatewithhandler (Cfallocatorgetdefault (), Kcfrunloopallactivities, YES,0, ^(Cfrunloopobserverref Observer, cfrunloopactivity activity) {NSLog (@"The Superintendent hears runloop--%zd", activity); }); //Add ObserverCfrunloopaddobserver (Cfrunloopgetcurrent (), observe, kcfrunloopdefaultmode); //CF Memory Management (Core Foundation) /*any function created with creat copy retain and other components 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