新建线程中run loop的autorelease池

来源:互联网 发布:电信首选网络类型 编辑:程序博客网 时间:2024/06/04 00:28

“我们每个新建的线程都会有一个默认的run loop,当这个线程被创建之后,会自动生成一个autorelease池,这个池会在run loop结束时释放,这个池是系统生成,我们无法操控,所以不进行其他retain或者copy操作的话,在线程中自动释放的对象的只存在于该线程本身,而ios这样的设计也很符合逻辑”


完全是骗人的,如果我们自己不创建autorelease pool的话,如果线程中有自动释放的对象,log中会打印类似

TestNSTimerRunloop[3663:5d03] *** __NSAutoreleaseNoPool(): Object 0x4b23760 of class __NSDate autoreleased with no pool in place - just leakingTestNSTimerRunloop[3663:5d03] *** __NSAutoreleaseNoPool(): Object 0x8a02560 of class __NSCFTimer autoreleased with no pool in place - just leakingTestNSTimerRunloop[3663:5d03] *** __NSAutoreleaseNoPool(): Object 0x4b237a0 of class __NSArrayI autoreleased with no pool in place - just leaking

所以说在网上看到某些文章后一定要亲自试一下,不是所有的都是正确的