search

Home  >  Q&A  >  body text

objective-c - 关于iOS内存管理的问题

@autoreleasepool {
    NSObject *obj = [[NSObject alloc] init];
}

以上代码在ARC模式下,obj对该对象有强引用,一旦出了这个作用域,强引用失效,对象被销毁。
同时该对象又被注册到autoreleasepool中,因为出了autoreleasepool的作用域,对象岂不是又要销毁一次???

PHP中文网PHP中文网2809 days ago440

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-04-18 09:42:57

    The scope of obj is the scope of the automatic release pool. It will not be used twice. After adding @autoreleasepool, the object is placed in the release pool

    reply
    0
  • Cancelreply