(嵌套)自动释放池的范围是什么?

编程入门 行业动态 更新时间:2024-10-28 03:30:45
本文介绍了(嵌套)自动释放池的范围是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在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.

更多推荐

(嵌套)自动释放池的范围是什么?

本文发布于:2023-08-04 22:57:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1300341.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:嵌套

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!