关于自动引用计数我需要了解什么?

发布于 2025-01-04 21:48:09 字数 507 浏览 1 评论 0原文

我有一个应用程序正在更新到最新版本的 Xcode,但遇到了与自动引用计数 (ARC) 相关的多个错误。

这些错误要求我将调用拉到例如 autorelease 并调整我编写的处理内存管理的其他代码。

Clang 文档内容如下:

[ARC]不提供循环收集器;用户必须明确管理生命周期。

……这让我很紧张。我过去一直被 Objective-C 内存管理问题所困扰,并且一直在努力证明代码中的每个 retainreleaseautorelease 的合理性。

现在,ARC 呼吁我坚定信念,改变我的内存管理语义。我需要了解什么才能建立对 ARC 内存管理的信心?

I have an application I am updating to the latest version of Xcode and am being hit by multiple errors related to Automatic Reference Counting (ARC).

The errors call me to pull calls to e.g., autorelease and tweaking other code I have written that deals with memory management.

The Clang documentation reads:

[ARC] does not provide a cycle collector; users must explicitly manage lifetime instead.

... which makes me very nervous. I've been bitten by Objective-C memory management issues in the past, and slaved over justifying every retain, release and autorelease in my code.

Now ARC is calling me to take a leap of faith in altering my memory management semantics. What do I need to know to establish faith in ARC's memory management?

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

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

发布评论

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

评论(1

想你的星星会说话 2025-01-11 21:48:09

命名约定。修复每个静态分析器问题并确保您的命名清晰且符合约定 - 这现在用作与编译器的通信。现在,这确实没有必要,但最好删除所有编译器和检查器警告,进行测试,确保您对命名感到满意,然后进行转换。这也意味着提高警告级别并解决问题。

避免属性详细信息:字典的深层复制在 Xcode 4.2 中给出分析错误

“避免属性”中的示例演示了以下内容的重要性类型安全、描述性方法名称,并确保包含翻译中使用的内容并使用严格的选择器匹配。选择:-Wstrict-selector-match。当您执行不安全的转换时,类型安全也会出现——很可能,您需要在程序的某些部分通过特殊转换来引入类型安全。

对非托管类型的悬空引用。在这里看到:将现有 CGColor 分配给 CGColor 属性适用于 iOS 模拟器,而不是 iOS 设备。为什么?

<块引用>

[ARC]不提供循环收集器;用户必须明确管理生命周期。

这是指强循环引用(例如相互依赖的对象)。这些将存在于您的旧程序中。仪器可以帮助您检测它们。

完成转换后,准备测试多个操作系统版本。

祝你好运!


额外:

什么使用ARC有什么优点和缺点?

Naming Conventions. Fix every static analyzer issue and make sure your naming is clear and matches the conventions - this now serves as communication to the compiler. Now, this really is not necessary, but it is good to remove all the compiler and checker warnings, test, ensure your are happy with the naming, then convert. That also means increasing your warning levels and fixing the issues.

Avoid Attributes Details here: Deep copy of dictionaries gives Analyze error in Xcode 4.2

The examples in "Avoid Attributes" demonstrate the importance of type safety, descriptive method names, and ensuring you include what you use in a translation and use strict selector matching. opt: -Wstrict-selector-match. Type safety will also come up when you perform unsafe conversions -- chances are, you will need to introduce type safety via special casting in some parts of your program.

Dangling References to Unmanaged types. Seen here: Assigning an existing CGColor to a CGColor property works in iOS Simulator, not iOS device. Why?

[ARC] does not provide a cycle collector; users must explicitly manage lifetime instead.

This refers to strong cyclic references (e.g. codependent objects). These would exist in your old program. Instruments can help you detect them.

After you have concluded the conversion, be prepared to test several OS versions.

Good Luck!


Extras:

What are the advantages and disadvantages of using ARC?

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