(嵌套)自动释放池的范围是什么? [英] What is the scope of (nested) autorelease pools?

查看:275
本文介绍了(嵌套)自动释放池的范围是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在for循环中创建一个自动释放池(在方法A中)。在循环的每次迭代,我调用另一个方法(方法B)。方法B向方法A返回一个自动释放对象。如果我在方法A的for循环中释放池,那么是否会释放从方法B发送的对象?

I'm creating an autorelease pool in a for loop (in method A). At each iteration of the loop, I'm calling another method (method B). Method B returns an autoreleased object to Method A. If I drain the pool within the for loop in Method A, will that release the objects sent from Method B?

谢谢!

推荐答案

是 - 任何时候发送对象 -autorelease 添加到最高级别的autorelease池。只要你不在方法B中创建任何新的自动释放池,或者在调用堆栈中进一步向下,方法A的池应该是最高级别的池。

Yes - any time an object is sent -autorelease, it's added to the highest level autorelease pool. As long as you aren't creating any new autorelease pools in method B or further down the call stack, method A's pool should be the highest level pool.

这篇关于(嵌套)自动释放池的范围是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆