gpt4 book ai didi

cocoa - NSOperation main 中的 NSAutoreleasePool?

转载 作者:行者123 更新时间:2023-12-03 16:01:21 24 4
gpt4 key购买 nike

+[NSThread detachNewThreadSelector:toTarget:withObject:] 的文档说:

For non garbage-collected applications, the method aSelector is responsible for setting up an autorelease pool for the newly detached thread and freeing that pool before it exits.

我的问题是,我是否需要在重写 -[NSOperation main] 方法中创建自己的 NSAutoreleasePool ,还是创建 NSAutoreleasePoolNSOperation 处理?

最佳答案

问得好,即使苹果自己的文档和示例代码对此也不是很清楚。我相信我已经找到了答案:

Because operations are Objective-C objects, you should always create an autorelease pool early in the implementation of your task code. An autorelease pool provides protection against the leaking of Objective-C objects that are autoreleased during your task’s execution. Although there might already be a pool in place by the time your custom code is executed, you should never rely on that behavior and should always provide your own.

基本上,即使可能有一个像 David 提到的那样的池,您仍然应该创建自己的池。

关于cocoa - NSOperation main 中的 NSAutoreleasePool?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/184409/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com