我在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.
更多推荐
(嵌套)自动释放池的范围是什么?
发布评论