zoukankan      html  css  js  c++  java
  • 关于autoreleasepool

    简单的说,每次事件处理时候开始的时候,ios会为我们自动生成一个autorelesepool,,结束的时候释放掉。

    之前我们有误解是只有在main程序中有一个autoreleasepool,我们代码中所有autorelease对象都在这个pool中,这个观点是不正确的。

     

    You have to understand the concept of a run-loop. The run loop in iOS waits for some event to happen and then it acts upon it. That event could be the user touching the screen, receiving a call, etc.

    For every such event that iOS handles, a new autorelease pool is created at the beginning and drained when the event processing is complete. Theoretically there could be any number of nested autorelease pools created by Cocoa Touch, but the main one you should know about is the event loop.

    Maybe this diagram from the Application Life Cycle will help.

    <!--[if !vml]-->UIKit event loop<!--[endif]-->.

    In pseudo-code, this boils down to,

    intUIApplicationMain(...){
    <!--[if !supportLineBreakNewLine]-->
    <!--[endif]-->
        while(!shouldQuitApplication){
    <!--[if !supportLineBreakNewLine]-->
    <!--[endif]-->
            Event*someEvent =// wait for next event;
    <!--[if !supportLineBreakNewLine]-->
    <!--[endif]-->
            NSAutoreleasePool*myPool =[[NSAutoreleasePool alloc] init];
    <!--[if !supportLineBreakNewLine]-->
    <!--[endif]-->
            // handle event
    <!--[if !supportLineBreakNewLine]-->
    <!--[endif]-->
            [myPool release];
    <!--[if !supportLineBreakNewLine]-->
    <!--[endif]-->
        }
    <!--[if !supportLineBreakNewLine]-->
    <!--[endif]-->
    }
    <!--[if !supportLineBreakNewLine]-->
    <!--[endif]-->

    <!--[if !supportLineBreakNewLine]-->
    <!--[endif]-->
     

    These are the event types in iOS

    UIEventTypeTouches,
    <!--[if !supportLineBreakNewLine]-->
    <!--[endif]-->
    UIEventTypeMotion,
    <!--[if !supportLineBreakNewLine]-->
    <!--[endif]-->
    UIEventTypeRemoteControl,

    <!--[if !supportLineBreakNewLine]--> 

    So after every touch, motion, or remote control event is processed, the pool will be drained.


    by anerevol

  • 相关阅读:
    松软科技web课堂:JavaScript 比较和逻辑运算符
    松软科技web课堂:JavaScript 布尔(逻辑)
    松软科技web课堂:随机Math.random()
    松软科技web课堂:JavaScript Math 对象
    松原网站建设,巨惠分享0元11月启动
    松原本地专业网站建设,公众号,微网站,小程序定制开发
    JavaScript 日期格式
    松软科技前端课堂:JavaScript 日期
    松软科技web课堂:JavaScript 数组迭代方法
    安装npm install app-inspector -g 提示错误
  • 原文地址:https://www.cnblogs.com/ydhliphonedev/p/2159139.html
Copyright © 2011-2022 走看看