仪器中的 NSAutoreleasePool 泄漏
如果之前有人问过这个问题,我深表歉意,但我还没有找到好的答案。
当我运行 Instruments 时,我在代码中的这一行(而不是主代码中)发现了泄漏:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
我一直在环顾四周并在某处读到这可能是一个错误。有人可以帮助我并分享一些关于此的信息吗?
我确实注意到我在 main 中也有相同的名字“pool”。
I do apologize if this have been asked before but i have not found a good answer.
When i run the Instruments i get a leak on this line in the code, not in main:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
I have been looking around and read somewhere that it may be a bug. Could someone please help me and share some light on this?
I did notice that i have the same name, "pool", in main also.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
名字并不重要;整个代码库中可能有数百个名为
pool
的变量。重要的是范围。通常,您会看到以下内容:
即您的泳池是否正在排空?
(
drain
存在于 iOS 上;请参阅 文档。但是,在所有情况下,最好使用@autoreleasepool{ ... }
;它适用于 ARC 和MRR。)The name doesn't matter; there may be hundreds of variables named
pool
throughout the codebase. What matters is scope.Typically, you'll see this:
I.e. is your pool being drained?
(
drain
exists on iOS; see the documentation. However, in all cases, it is better to use@autoreleasepool{ ... }
; it works in ARC and MRR.)我也遇到了这个问题,这是我学习编码第一天的第一个问题!
我所做的就是彻底删除以以下内容开头的整行:
将其替换为:
然后我在程序底部删除了:
然后用波浪括号封闭。
我不知道它为什么有效,我第一天记得,但它运行示例书中的程序很好。
I had this problem as well, my first problem on the first day learning how to code!
All I did was remove outright the entire line starting with:
replace it with:
Then I deleted at the bottom of my program:
Then closed off with the squiggly brackets.
I don't know why it works, my first day remember but it runs my program from the example book fine.