<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      iOS 學習@autoreleasepool{}

      " ojc-c 是通過一種"referring counting"(引用計數)的方式來管理內存的, 對象在開始分配內存(alloc)的時候引用計數為一,以后每當碰到有alloc,new,[mutable]copy,retain的時候引用計數都會加一, 每當碰到release和autorelease的時候引用計數就會減一,如果此對象的計數變為了0, 就會被系統銷毀. "網摘

       自從ARC以后 我們不需要手動釋放內存 但是有時候 我們仍然需要手動釋放,以便更加精準的管理內存問題.

      這里 就用到@autoreleasepool{} //自動釋放內存池 “釋放池”  

      (1)@autoreleasepool{}  按棧的順序釋放內存 銷毀對象,  可以嵌套使用

      (2)@autoreleasepool{}  相當于 做 autorelease / release 操作,如果把已經autorelease / release 的對象做 釋放池操作 就會報野指針錯誤. (ARC 好像這個問題就很少有了吧…)

      舉例子

      (1)循環創建臨時變量 或者說 短時間內創建大量變量  應該考慮使用 @autoreleasepool{}

       這個例子 真是不勝枚舉啊

      - (void)viewDidLoad {
          [super viewDidLoad];
          [self test2];
      }
      
      - (void)test2
      {
           CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
          for (int i = 0; i < 10000000; ++i) {
              @autoreleasepool {
                  MethodDetailMusic *music = [[MethodDetailMusic alloc]init];
                  music.title = @"haha";
           //       NSLog(@"%@", music.title);
              }
          }
           NSLog(@"end - %f", CFAbsoluteTimeGetCurrent() - start);
      }

      (1)是否有 @autoreleasepool {} 拿 Leak工具 跑了一次 看對比截圖 

      看前面幾個驚險的MB  就看出差別了吧

      (2)@autoreleasepool {} 放在循環體外 和循環體內還是有很大差別的

      
      

      //10000  

      2016-08-18 11:44:44.558 LearningTheroyDemo[40012:6355283] end - 0.002388

      2016-08-18 11:45:49.970 LearningTheroyDemo[40032:6356878] end - 0.002540

      
      

      //10000000(從這可以看出枚舉量越大 效率差別越明顯)

      2016-08-18 11:47:30.521 LearningTheroyDemo[40071:6359862] end - 2.655450

      2016-08-18 11:48:14.521 LearningTheroyDemo[40080:6361041] end - 2.932974

       

      (2) 自己創建的線程 "detach thread", 有相對來說 很多需要釋放的對象,應該使用@autoreleasepool{} 否則內存會升高,但是 如果這個非關聯線程 "detach thread"沒有使用到cocoa的相關調用 就不必創建 autorelease pool.

           第二段,大概是說如果創建POSIX 線程 做二級線程 這個就不能使用 cocoa ,不能使用 @autoreleasepool{}, 除非 cocoa

      在多線程里面,并且是一級線程里面的對象.所以 在二級POSIX線程里面要使用cocoa必須有這個所謂的一級線程,并且要立即銷毀.所以 你要使用 cococa 要確保是在多線程里面 如何判斷 bla bla.

         我覺得 我翻譯的還行  沒出什么原則的bug 網上好多帖子 說的 不是不對 就是不準 , 根本沒說明白 detach thread 里面 到底 能不能用 @autoreleasepool{} ? 簡單的來說 如果 創建了 很多需要釋放的對象 就可以用啊 ,因為 我們常用的多線程(NSOperation NSthread  GCD ) 是滿足需求沒有例外的 ,就是 官方文檔提到的這個 "POSIX thread" ( 是調用pthread_create來創建的線程 C語言底層部分的知識了此處不再擴展,需要深究時候及時學習)不能使用@autoreleasepool{},但是也給了一個 處理方案...

         If you are making Cocoa calls outside of the Application Kit’s main thread—for example if you create a Foundation-only application or if you detach a thread—you need to create your own autorelease pool.

      If your application or thread is long-lived and potentially generates a lot of autoreleased objects, you should periodically drain and create autorelease pools (like the Application Kit does on the main thread); otherwise, autoreleased objects accumulate and your memory footprint grows. If, however, your detached thread does not make Cocoa calls, you do not need to create an autorelease pool.

      Note

      If you are creating secondary threads using the POSIX thread APIs instead of NSThread objects, you cannot use Cocoa, including NSAutoreleasePool, unless Cocoa is in multithreading mode. Cocoa enters multithreading mode only after detaching its first NSThread object. To use Cocoa on secondary POSIX threads, your application must first detach at least one NSThread object, which can immediately exit. You can test whether Cocoa is in multithreading mode with the NSThread class method isMultiThreaded.      

       

      參考

      https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSAutoreleasePool_Class/

      http://www.rzrgm.cn/CoderAlex/p/5232357.html

      posted on 2016-08-18 15:08  ACM_Someone like you  閱讀(547)  評論(0)    收藏  舉報

      導航

      主站蜘蛛池模板: 激情综合色区网激情五月| 国产精品一区二区三区性色| 日本人成精品视频在线| 久久国产精品亚洲精品99| 99久久国产精品无码| 欧美一区二区三区成人久久片| 丝袜人妻一区二区三区网站| 91麻豆亚洲国产成人久久| 玩弄放荡人妻少妇系列| 国精偷拍一区二区三区| 国产精品熟妇视频国产偷人| 国产亚洲精品成人无码精品网站| 精品久久久久无码| 成人免费区一区二区三区| 久久99国产一区二区三区| 国产av不卡一区二区| 国产成人a在线观看视频免费 | 亚洲欧洲日产国产av无码| 综合欧美视频一区二区三区| 乱60一70归性欧老妇| 男女吃奶做爰猛烈紧视频| 亚洲老女人区一区二视频| 国产精品普通话国语对白露脸| 亚洲中文字幕无码爆乳APP| 成人精品日韩专区在线观看| 亚洲 国产 制服 丝袜 一区| 国产精品天干天干综合网| 日韩高清福利视频在线观看| 国产精品久久久久aaaa| 高潮精品熟妇一区二区三区| 欧美午夜成人片在线观看| 日本高清在线观看WWW色| 欧美视频二区欧美影视| 色8久久人人97超碰香蕉987| 美乳丰满人妻无码视频| 丁香婷婷综合激情五月色| 毛片免费观看视频| 青青草无码免费一二三区| 青青草成人免费自拍视频| 国产成人精品手机在线观看| av天堂久久精品影音先锋|