# \#arc

**URL:** https://forums.swift.org/tag/arc/417.md

[Latest](https://forums.swift.org/latest.md) · [Categories](https://forums.swift.org/categories.md) · [Tags](https://forums.swift.org/tags.md)

---

## [Difference between CFGetRetainCount v \_getRetainCount](https://forums.swift.org/t/difference-between-cfgetretaincount-v-getretaincount/81995)

<div class="topic-metadata">

**Author:** [@realmtai](https://forums.swift.org/u/realmtai)\
**Replies:** 9\
**Last updated:** [September 8, 2025, 7:37pm UTC](https://forums.swift.org/t/difference-between-cfgetretaincount-v-getretaincount/81995 "2025-09-08T19:37:03Z")

</div>

Hello folks, \[Context\] I have an iOS project that has a few internal actors. These actors are persisted across the entire lifetime of the application. This is a possible source that could cause a retain cycle. \[Curren…

---

## [(De)Initialization of Character inside of UnsafeMutableBufferPointer](https://forums.swift.org/t/de-initialization-of-character-inside-of-unsafemutablebufferpointer/81398)

<div class="topic-metadata">

**Author:** [@hex-ley](https://forums.swift.org/u/hex-ley)\
**Replies:** 3\
**Last updated:** [July 30, 2025, 1:50pm UTC](https://forums.swift.org/t/de-initialization-of-character-inside-of-unsafemutablebufferpointer/81398 "2025-07-30T13:50:16Z")

</div>

Hi everyone, I'm currently implementing a custom data structure based on two buffers, where each holds the characters left and right to the cursor respectively. Sure I could just use \[Character\] arrays instead. But sinc…

---

## [\[ARC\] Unowned Reference Count and Deallocation Timing](https://forums.swift.org/t/arc-unowned-reference-count-and-deallocation-timing/81228)

<div class="topic-metadata">

**Author:** [@poro](https://forums.swift.org/u/poro)\
**Replies:** 9\
**Last updated:** [July 26, 2025, 3:15pm UTC](https://forums.swift.org/t/arc-unowned-reference-count-and-deallocation-timing/81228 "2025-07-26T15:15:12Z")

</div>

Hi all, I’m digging into the details of how Swift ARC manages object lifetime with respect to strong, weak, and unowned references. Based on RefCount.h and various runtime comments, my current understanding is as follo…

---

## [Could C++ have ARC?](https://forums.swift.org/t/could-c-have-arc/79387)

<div class="topic-metadata">

**Author:** [@audulus](https://forums.swift.org/u/audulus)\
**Replies:** 2\
**Last updated:** [April 22, 2025, 4:48am UTC](https://forums.swift.org/t/could-c-have-arc/79387 "2025-04-22T04:48:29Z")

</div>

Part of my codebase is C++ called from Swift and I've gotta do some refcounting myself. Wouldn't it be great if C++ objects could be ARC'd like Swift and ObjC objects? Something like: \[\[arc\]\] class MyCoolThing { ..…

---

## [Pros and cons of Unmanaged, UnsafePointers and Data?](https://forums.swift.org/t/pros-and-cons-of-unmanaged-unsafepointers-and-data/74646)

<div class="topic-metadata">

**Author:** [@RussBaz](https://forums.swift.org/u/RussBaz)\
**Replies:** 13\
**Last updated:** [March 12, 2025, 9:04am UTC](https://forums.swift.org/t/pros-and-cons-of-unmanaged-unsafepointers-and-data/74646 "2025-03-12T09:04:26Z")

</div>

Hi. Can someone briefly explain how to pick one vs the other? Also, can anyone clarify some of the ARC terminology, such as balanced vs unbalanced retain? As an example of what I am doing - I am creating a mutable byte …

---

## [Why retain/release pair is not removed in this particular case?](https://forums.swift.org/t/why-retain-release-pair-is-not-removed-in-this-particular-case/77206)

<div class="topic-metadata">

**Author:** [@shivatinker](https://forums.swift.org/u/shivatinker)\
**Replies:** 6\
**Last updated:** [January 15, 2025, 9:56pm UTC](https://forums.swift.org/t/why-retain-release-pair-is-not-removed-in-this-particular-case/77206 "2025-01-15T21:56:59Z")

</div>

Hey there! I have some performance critical code in my project, and I noticed that 20-30% of the time on the hot path is spent on retain/release calls. I have reduced the example to this code: protocol P { func tak…

---

## [Does UnsafePointer create a weak reference to the referenced object?](https://forums.swift.org/t/does-unsafepointer-create-a-weak-reference-to-the-referenced-object/75197)

<div class="topic-metadata">

**Author:** [@RussBaz](https://forums.swift.org/u/RussBaz)\
**Replies:** 17\
**Last updated:** [October 9, 2024, 7:16pm UTC](https://forums.swift.org/t/does-unsafepointer-create-a-weak-reference-to-the-referenced-object/75197 "2024-10-09T19:16:02Z")

</div>

Hi. Does a pointer object create a strong reference to an object for ARC to retain it, or is it a (unsafe) weak reference? I suspect it is the latter, but please confirm. Also, does UnsafeMutablePointer.initialize(to:) …

---

## [How to know if a value type includes heap allocations and ref counting](https://forums.swift.org/t/how-to-know-if-a-value-type-includes-heap-allocations-and-ref-counting/72919)

<div class="topic-metadata">

**Author:** [@ConfusedByCode](https://forums.swift.org/u/ConfusedByCode)\
**Replies:** 15\
**Last updated:** [July 5, 2024, 12:53am UTC](https://forums.swift.org/t/how-to-know-if-a-value-type-includes-heap-allocations-and-ref-counting/72919 "2024-07-05T00:53:56Z")

</div>

I've been trying to improve my understanding Swift's performance characteristics. John McCall's WWDC talk, Exploring Swift Performance, from this year's WWDC is an excellent resource, and I highly recommend it for anyone…

---

## [ARC messes with \`OS\_object\` manipulation](https://forums.swift.org/t/arc-messes-with-os-object-manipulation/72717)

<div class="topic-metadata">

**Author:** [@nmgswift](https://forums.swift.org/u/nmgswift)\
**Replies:** 12\
**Last updated:** [June 24, 2024, 8:59pm UTC](https://forums.swift.org/t/arc-messes-with-os-object-manipulation/72717 "2024-06-24T20:59:52Z")

</div>

Hello! I'm using Swift and Swift Package Manager to play around with the Objective-C runtime to try and understand more about how it works. I came across the object\_setClass function and found it pretty neat. Unfortunate…

---

## [Bug in Embedded/ARC/WebAssembly combination?](https://forums.swift.org/t/bug-in-embedded-arc-webassembly-combination/71967)

<div class="topic-metadata">

**Author:** [@turbolent](https://forums.swift.org/u/turbolent)\
**Replies:** 5\
**Last updated:** [June 7, 2024, 8:42pm UTC](https://forums.swift.org/t/bug-in-embedded-arc-webassembly-combination/71967 "2024-06-07T20:42:47Z")

</div>

I'm currently trying out the Swift on WebAssembly and the new Embedded feature, after reading Some feedback from my short experience with SwiftWasm - #5 by Max\_Desiatov and Embedded Swift. However, I'm seeing some stran…

---

## [Swift Classes without ARC](https://forums.swift.org/t/swift-classes-without-arc/66636)

<div class="topic-metadata">

**Author:** [@joehink](https://forums.swift.org/u/joehink)\
**Replies:** 17\
**Last updated:** [November 1, 2023, 10:56am UTC](https://forums.swift.org/t/swift-classes-without-arc/66636 "2023-11-01T10:56:10Z")

</div>

Hey all, I used Swift macros to create make using classes without ARC possible. I called it NRC (no reference counting). Let me know what you think! // Declaration @NRC( members: \[ "var y": Int.self, …

---

## [performSelector("retainCount")](https://forums.swift.org/t/performselector-retaincount/68055)

<div class="topic-metadata">

**Author:** [@tera](https://forums.swift.org/u/tera)\
**Replies:** 6\
**Last updated:** [October 25, 2023, 10:11pm UTC](https://forums.swift.org/t/performselector-retaincount/68055 "2023-10-25T22:11:10Z")

</div>

The other thread prompted me to a question of calling the prohibited retainCount – could be useful for debugging purposes. I know a few techniques to grab retainCount of an object (e.g. calling through a C helper that re…

---

## [Passing weak references to JSContext](https://forums.swift.org/t/passing-weak-references-to-jscontext/65077)

<div class="topic-metadata">

**Author:** [@soumyamahunt](https://forums.swift.org/u/soumyamahunt)\
**Replies:** 2\
**Last updated:** [May 22, 2023, 10:37am UTC](https://forums.swift.org/t/passing-weak-references-to-jscontext/65077 "2023-05-22T10:37:18Z")

</div>

I am using JavaScriptCore to pass data between javascript and swift. Here is a minimal reproducible example of what I am trying to accomplish: class SomeClass: NSObject { let context: JSContext override init() …

---

## [ARC deinit time question](https://forums.swift.org/t/arc-deinit-time-question/64522)

<div class="topic-metadata">

**Author:** [@zienag](https://forums.swift.org/u/zienag)\
**Replies:** 6\
**Last updated:** [April 28, 2023, 1:21pm UTC](https://forums.swift.org/t/arc-deinit-time-question/64522 "2023-04-28T13:21:17Z")

</div>

Greetings! I know that release calls are not guaranteed to happen at scope/function end, but is there a guarantee that it will happen before parent function continues execution? For example: class A { deinit { print…

---

## [How ARC does resolve Strong Reference Cycles for Closures that don't reference class self?](https://forums.swift.org/t/how-arc-does-resolve-strong-reference-cycles-for-closures-that-dont-reference-class-self/64171)

<div class="topic-metadata">

**Author:** [@bytedriver](https://forums.swift.org/u/bytedriver)\
**Replies:** 18\
**Last updated:** [April 6, 2023, 10:30pm UTC](https://forums.swift.org/t/how-arc-does-resolve-strong-reference-cycles-for-closures-that-dont-reference-class-self/64171 "2023-04-06T22:30:23Z")

</div>

Hi Community! I have a question about the Strong Reference Cycles for Closures. The example below shows how you can create a strong reference cycle when using a closure that references self. class HTMLElement { l…

---

## [Deep recursion in deinit should not happen](https://forums.swift.org/t/deep-recursion-in-deinit-should-not-happen/54987)

<div class="topic-metadata">

**Author:** [@sspringer](https://forums.swift.org/u/sspringer)\
**Replies:** 42\
**Last updated:** [January 21, 2023, 2:30pm UTC](https://forums.swift.org/t/deep-recursion-in-deinit-should-not-happen/54987 "2023-01-21T14:30:49Z")

</div>

When the removal of the only reference to an item triggers the removal of the only reference to another item and so on, we get a stack overflow of the deinits (could be implicit deinits just created by the compiler for r…

---

## [ARC overhead when wrapping a class in a struct which is only borrowed](https://forums.swift.org/t/arc-overhead-when-wrapping-a-class-in-a-struct-which-is-only-borrowed/62037)

<div class="topic-metadata">

**Author:** [@Karl](https://forums.swift.org/u/Karl)\
**Replies:** 29\
**Last updated:** [December 20, 2022, 6:26pm UTC](https://forums.swift.org/t/arc-overhead-when-wrapping-a-class-in-a-struct-which-is-only-borrowed/62037 "2022-12-20T18:26:49Z")

</div>

I have a reference-counted type which I would like to wrap in a struct and pass to a closure. The underlying type is a storage object, and the wrapper exposes some convenient APIs for it. func forward(\_ storage: Storage…

---

## [SE-0366 (second review): \`take\` operator to end the lifetime of a variable binding](https://forums.swift.org/t/se-0366-second-review-take-operator-to-end-the-lifetime-of-a-variable-binding/61021)

<div class="topic-metadata">

**Author:** [@hborla](https://forums.swift.org/u/hborla)\
**Replies:** 23\
**Last updated:** [December 7, 2022, 9:24pm UTC](https://forums.swift.org/t/se-0366-second-review-take-operator-to-end-the-lifetime-of-a-variable-binding/61021 "2022-12-07T21:24:54Z")

</div>

Hello, Swift community! The second review of SE-0366: take operator to end the lifetime of a variable binding begins now and runs through November 8th, 2022. The changes to the first reviewed proposal include: move …

---

## [SE-0366: Move Function + "Use After Move" Diagnostic](https://forums.swift.org/t/se-0366-move-function-use-after-move-diagnostic/59202)

<div class="topic-metadata">

**Author:** [@hborla](https://forums.swift.org/u/hborla)\
**Replies:** 176\
**Last updated:** [August 16, 2022, 12:28am UTC](https://forums.swift.org/t/se-0366-move-function-use-after-move-diagnostic/59202 "2022-08-16T00:28:24Z")

</div>

Hello, Swift community! The review of SE-0366: Move Function + "Use After Move" Diagnostic begins now and runs through August 8th, 2022. Reviews are an important part of the Swift evolution process. All review feedback…

---

## [\[Returned for revision\] SE-0366: Move Operation + "Use After Move" Diagnostic](https://forums.swift.org/t/returned-for-revision-se-0366-move-operation-use-after-move-diagnostic/59687)

<div class="topic-metadata">

**Author:** [@hborla](https://forums.swift.org/u/hborla)\
**Replies:** 0\
**Last updated:** [August 16, 2022, 12:21am UTC](https://forums.swift.org/t/returned-for-revision-se-0366-move-operation-use-after-move-diagnostic/59687 "2022-08-16T00:21:18Z")

</div>

Hello, Swift community! The review for SE-0366: Move Operation + “Use After Move” Diagnostic ended on August 8th. The Language Workgroup decided that the proposal is returned for revision. Based on early review feedbac…

---

## [ARC, tail recursion](https://forums.swift.org/t/arc-tail-recursion/57054)

<div class="topic-metadata">

**Author:** [@RonAvitzur](https://forums.swift.org/u/RonAvitzur)\
**Replies:** 13\
**Last updated:** [May 2, 2022, 12:16am UTC](https://forums.swift.org/t/arc-tail-recursion/57054 "2022-05-02T00:16:44Z")

</div>

While looking at a stack overflow crash, it looks like var leftMost: Expr { count == 0 ? self : args\[0\].leftMost } is not benefiting from tail call optimization. final class Expr : Sequence, Equatable, Hashable { …

---

## [Tools for determining ARC overhead?](https://forums.swift.org/t/tools-for-determining-arc-overhead/53567)

<div class="topic-metadata">

**Author:** [@lmcd](https://forums.swift.org/u/lmcd)\
**Replies:** 2\
**Last updated:** [November 19, 2021, 2:15pm UTC](https://forums.swift.org/t/tools-for-determining-arc-overhead/53567 "2021-11-19T14:15:58Z")

</div>

Just curious what tools/methods people are using for determining how much of an impact ARC is having in critical paths of their code? Just Xcode instruments? Is there an easy way to visualise where all the retain/releas…

---

## [Why is implicit \`\[weak self\]\` not the norm?](https://forums.swift.org/t/why-is-implicit-weak-self-not-the-norm/49232)

<div class="topic-metadata">

**Author:** [@GabrielBrodersen](https://forums.swift.org/u/GabrielBrodersen)\
**Replies:** 19\
**Last updated:** [June 9, 2021, 1:48am UTC](https://forums.swift.org/t/why-is-implicit-weak-self-not-the-norm/49232 "2021-06-09T01:48:36Z")

</div>

After browsing the web for this question and learning about memory retain cycles in Swift (and how to deal with them), it is easy to get the impression that adding the capture list \[weak self\] is often the solution and r…

---

## [Retain count set to 2 and no deinit called](https://forums.swift.org/t/retain-count-set-to-2-and-no-deinit-called/43571)

<div class="topic-metadata">

**Author:** [@Erick](https://forums.swift.org/u/Erick)\
**Replies:** 30\
**Last updated:** [January 12, 2021, 9:03am UTC](https://forums.swift.org/t/retain-count-set-to-2-and-no-deinit-called/43571 "2021-01-12T09:03:20Z")

</div>

This rabbit hole is way bigger, but, in the mean time, I have two questions: Why is the deinit code never called here? Why is the retain count returned: 2? Code is below and compiled in macOS Big Sur with the latest e…

---

## [Copy-on-write and M1 optimizations](https://forums.swift.org/t/copy-on-write-and-m1-optimizations/43470)

<div class="topic-metadata">

**Author:** [@crontab](https://forums.swift.org/u/crontab)\
**Replies:** 4\
**Last updated:** [January 1, 2021, 7:51pm UTC](https://forums.swift.org/t/copy-on-write-and-m1-optimizations/43470 "2021-01-01T19:51:32Z")

</div>

There's information that the M1 makes refcounting faster than before, i.e. on the Intel platforms. People reported that some benchmarks show the improvement of specifically refcount increment/decrement operations up to 5…

---

## [Why Reference Counters All Start with +1?](https://forums.swift.org/t/why-reference-counters-all-start-with-1/42372)

<div class="topic-metadata">

**Author:** [@daksyonov](https://forums.swift.org/u/daksyonov)\
**Replies:** 2\
**Last updated:** [December 1, 2020, 6:23am UTC](https://forums.swift.org/t/why-reference-counters-all-start-with-1/42372 "2020-12-01T06:23:06Z")

</div>

This question can seem a bit theoretical, but while looking through ARC subject I discovered that as per swift/stdlib/public/SwiftShims/RefCount.h - The strong RC is stored as an extra count: when the physical field is…

---

## [Does autoclosure respect weak'ness of a captured variable?](https://forums.swift.org/t/does-autoclosure-respect-weakness-of-a-captured-variable/39724)

<div class="topic-metadata">

**Author:** [@Kentzo](https://forums.swift.org/u/Kentzo)\
**Replies:** 2\
**Last updated:** [November 12, 2020, 7:23pm UTC](https://forums.swift.org/t/does-autoclosure-respect-weakness-of-a-captured-variable/39724 "2020-11-12T19:23:13Z")

</div>

I'm confused whether in the following example the weakInstance autoclosure captures self weakly and can therefore return nil: func perform(weakInstance: @autoclosure () -\> SomeType?) { weakInstance() // \<- Can this…

---

## [Does inout affect reference count on a class?](https://forums.swift.org/t/does-inout-affect-reference-count-on-a-class/41061)

<div class="topic-metadata">

**Author:** [@1oo7](https://forums.swift.org/u/1oo7)\
**Replies:** 4\
**Last updated:** [October 9, 2020, 11:18pm UTC](https://forums.swift.org/t/does-inout-affect-reference-count-on-a-class/41061 "2020-10-09T23:18:00Z")

</div>

What is the difference between passing an instance of a class into a function with inout as opposed to without inout? E.g.: func doSomething(with viewController: UIViewController) { ... } vs. func doSomething(with vi…

---

## [Disabling ARC for custom literals](https://forums.swift.org/t/disabling-arc-for-custom-literals/40787)

<div class="topic-metadata">

**Author:** [@evanireland](https://forums.swift.org/u/evanireland)\
**Replies:** 8\
**Last updated:** [October 8, 2020, 2:34am UTC](https://forums.swift.org/t/disabling-arc-for-custom-literals/40787 "2020-10-08T02:34:16Z")

</div>

Is there a way to disable ARC for "custom" literals? For example: class B { let value: Bool private init(\_ b: Bool) { value = b } public static let TRUE = B(true) public static let FALSE = B(false) } If the object…
