zoukankan      html  css  js  c++  java
  • autoreleasing on a thread

    So basically, if you are running on OS X 10.9+ or iOS 7+, autoreleasing on a thread without a pool should not lead to a leak. This is not documented and is an internal implementation detail, so be careful relying on this as Apple could change it in a future OS. However, I don't see any reason why they would remove this feature as it is simple and only has benefits and no downsides, unless they completely re-write the way autorelease pools work or something.

    The Objective-C runtime is open-source so you can read the source to see what's going on. The latest version of the runtime (646, which shipped with OS X 10.10 and iOS 8) does indeed add a pool if you perform an autorelease without a pool on the current thread. In NSObject.mm:

    static __attribute__((noinline))
    id *autoreleaseNoPage(id obj)
    {
        // No pool in place.
        assert(!hotPage());
    
        if (obj != POOL_SENTINEL  &&  DebugMissingPools) {
            // We are pushing an object with no pool in place, 
            // and no-pool debugging was requested by environment.
            _objc_inform("MISSING POOLS: Object %p of class %s "
                         "autoreleased with no pool in place - "
                         "just leaking - break on "
                         "objc_autoreleaseNoPool() to debug", 
                         (void*)obj, object_getClassName(obj));
            objc_autoreleaseNoPool(obj);
            return nil;
        }
    
        // Install the first page.
        AutoreleasePoolPage *page = new AutoreleasePoolPage(nil);
        setHotPage(page);
    
        // Push an autorelease pool boundary if it wasn't already requested.
        if (obj != POOL_SENTINEL) {
            page->add(POOL_SENTINEL);
        }
    
        // Push the requested object.
        return page->add(obj);
    }
  • 相关阅读:
    C# 对Outlook2010进行二次开发
    利用AForge.NET 调用电脑摄像头进行拍照
    SQL2012 提示评估已过期 解决方案- sql server问题
    图片转换PDF
    [转载]理解weight decay
    ATTENTION NETWORK分析
    sys.stdout.write和print和sys.stdout.flush
    Flutter免费(视频)教程汇总
    Windows核心编程随笔
    .NET家族
  • 原文地址:https://www.cnblogs.com/feng9exe/p/7240897.html
Copyright © 2011-2022 走看看