GNUStep NSAutoreleasePool 不兼容

发布于 2024-08-06 12:14:11 字数 479 浏览 3 评论 0原文

根据另一篇 Stack Overflow 帖子drain message 是 Apple 独有的调用:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog (@"Hello");
[pool drain];
return 0;

drain 替换为 release 是否安全?我正在尝试移植一个 Objective-C 应用程序以在 Linux(目前是 Ubuntu)上运行。我应该在开始之前就放弃吗? (我在尝试让 NSURLConnection 工作时已经遇到问题)

According to another Stack Overflow post the drain message is an Apple-only call:

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSLog (@"Hello");
[pool drain];
return 0;

Is it safe to replace drain with release? I am trying to port an Objective-C application to run on Linux (Ubuntu at the moment). Should I give up even before I have started? (I'm already having issues trying to get NSURLConnection working)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇纵 2024-08-13 12:14:11

来自 Apple 的 drain 文档:

[...]此方法的行为与release相同。 [...]

因此,耗尽自动释放池意味着不可避免地要重新分配它。在我看来,Apple 应该弃用 drain,因为它只会造成混乱。

但:

特殊注意事项:
在垃圾收集环境中,release
是一个空操作,所以除非你不想
给收藏家一个提示
在任何代码中使用drain很重要
可以编译为
垃圾收集环境。

From Apple's documentation of drain:

[...] this method behaves the same as release. [...]

So draining an autorelease pool means deallocating it inevitably. In my opinion, Apple should deprecate drain since it only creates confusion.

But:

Special Considerations:
In a garbage-collected environment, release
is a no-op, so unless you do not want
to give the collector a hint it is
important to use drain in any code
that may be compiled for a
garbage-collected environment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文