# atomic reference counting

Atomic reference counting is a computing technique that uses an atomic counter to track references to an object, with operations for incrementing, decrementing, and detecting when the count reaches zero.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## FFM Design Patterns

DevFeed: [FFM Design Patterns](<https://devfeed.tech/articles/ffm-design-patterns-134459.md>)

Original publisher: [Read original article](<https://dfa1.github.io/articles/ffm-design-patterns.html>)

Author: Davide Angelocola

Published: 2026-11-15T00:00:00Z

Content type: article

Language: en

Sources: [Davide Angelocola](<https://devfeed.tech/sources/davide-angelocola.md>)

Topics: [Memory Safety](<https://devfeed.tech/topics/memory-safety.md>), [software-architecture](<https://devfeed.tech/topics/software-architecture.md>), [atomic reference counting](<https://devfeed.tech/topics/atomic-reference-counting.md>), [coding patterns](<https://devfeed.tech/topics/coding-patterns.md>), [Test-driven development](<https://devfeed.tech/topics/tdd.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [c](<https://devfeed.tech/tags/c.md>), [design](<https://devfeed.tech/tags/design.md>), [design-patterns](<https://devfeed.tech/tags/design-patterns.md>), [java](<https://devfeed.tech/tags/java.md>), [memory](<https://devfeed.tech/tags/memory.md>), [patterns](<https://devfeed.tech/tags/patterns.md>), [project-panama](<https://devfeed.tech/tags/project-panama.md>)

### AI overview

The draft's central rule is to make each native pointer's ownership and lifetime explicit: use confined arenas for call-scoped memory, platform layouts for C types such as `size_t`, and wrapper patterns for owned, transferred, borrowed, parent-owned, or shared resources. It illustrates why parent-child cleanup order matters, why close operations may need to refuse before releasing state, and why shared references need reference counting to prevent use-after-free races. Longer-lived buffers and upcall stubs must live as long as the native object that uses them; callbacks must catch failures, and `critical` downcalls must neither call back into Java nor block. It also recommends translating library-specific errors at the Java boundary, keeping raw FFM bindings separate from an idiomatic public API, and granting native access through launcher configuration. The text distinguishes implemented project patterns from proposals, including refcounting for shared dictionary references, and notes known race and lifecycle limitations.

### Source excerpt

Java's Foreign Function & Memory API, one of the outcomes of Project Panama, is well documented as an API. Wrapping a real C library with it is a different problem: who owns each pointer, who frees it, and when, is left to you. These are the patterns I use.

## Using OxCaml to implement type-safe reference counting between OCaml and Python

DevFeed: [Using OxCaml to implement type-safe reference counting between OCaml and Python](<https://devfeed.tech/articles/using-oxcaml-to-implement-type-safe-reference-counting-between-ocaml-and-python-20199.md>)

Original publisher: [Read original article](<https://blog.janestreet.com/oxcaml-typesafe-reference-counting-python/>)

Author: Nicolas Trangez

Published: 2026-06-15T00:00:00Z

Content type: article

Language: en

Sources: [Jane Street](<https://devfeed.tech/sources/jane-street.md>)

Topics: [OCaml](<https://devfeed.tech/topics/ocaml.md>), [typesafety](<https://devfeed.tech/topics/typesafety.md>), [Python](<https://devfeed.tech/topics/python.md>), [atomic reference counting](<https://devfeed.tech/topics/atomic-reference-counting.md>), [Machine learning](<https://devfeed.tech/topics/machine-learning.md>)

Tags: [data-analysis](<https://devfeed.tech/tags/data-analysis.md>), [data-types](<https://devfeed.tech/tags/data-types.md>), [high-performance](<https://devfeed.tech/tags/high-performance.md>), [machine-learning](<https://devfeed.tech/tags/machine-learning.md>), [memory](<https://devfeed.tech/tags/memory.md>), [memory-management](<https://devfeed.tech/tags/memory-management.md>), [ocaml](<https://devfeed.tech/tags/ocaml.md>), [parallelism](<https://devfeed.tech/tags/parallelism.md>), [python](<https://devfeed.tech/tags/python.md>), [reference](<https://devfeed.tech/tags/reference.md>), [type-safe](<https://devfeed.tech/tags/type-safe.md>)

### AI overview

Jane Street's PyOCaml bridge can delay Python object deallocation when Python objects are represented as OCaml values, which is problematic for large data frames or scarce resources such as GPU memory. The excerpt says OxCaml extensions let library authors encode prompt deallocation in a typesafe way, allowing the compiler to rule out Python programs with these promptness problems. The approach uses explicit reference counting between Python and OCaml and draws on borrowing; the excerpt begins explaining Python's reference-counted object lifecycle but cuts off before detailing the implementation.

### Source excerpt

Jane Street is known for being an OCaml shop, but for years now Python has been our second major programming language, acting as the primary tool for data analysis and (especially importantly these days) machine learning. Most of our traders and researchers think and write in Python, even as the majority of our infrastructure is written in OCaml.

## Improving the usability of C libraries in Swift

DevFeed: [Improving the usability of C libraries in Swift](<https://devfeed.tech/articles/improving-the-usability-of-c-libraries-in-swift-2931.md>)

Original publisher: [Read original article](<https://swift.org/blog/improving-usability-of-c-libraries-in-swift/>)

Author: Doug Gregor

Published: 2026-01-22T12:00:00Z

Content type: tutorial

Language: en

Sources: [Swift.org](<https://devfeed.tech/sources/swift-org.md>)

Topics: [Swift](<https://devfeed.tech/topics/swift.md>), [Memory Safety](<https://devfeed.tech/topics/memory-safety.md>), [atomic reference counting](<https://devfeed.tech/topics/atomic-reference-counting.md>), [Null-Safety](<https://devfeed.tech/topics/null-safety.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [c](<https://devfeed.tech/tags/c.md>), [functions](<https://devfeed.tech/tags/functions.md>), [gpu](<https://devfeed.tech/tags/gpu.md>), [graphics-processing-unit](<https://devfeed.tech/tags/graphics-processing-unit.md>), [headers](<https://devfeed.tech/tags/headers.md>), [interface](<https://devfeed.tech/tags/interface.md>), [interoperability](<https://devfeed.tech/tags/interoperability.md>), [libraries](<https://devfeed.tech/tags/libraries.md>), [pointers](<https://devfeed.tech/tags/pointers.md>), [safety](<https://devfeed.tech/tags/safety.md>), [swift](<https://devfeed.tech/tags/swift.md>), [usability](<https://devfeed.tech/tags/usability.md>), [webgpu](<https://devfeed.tech/tags/webgpu.md>)

### AI overview

Swift's API notes and Clang bridging annotations can make existing C libraries safer and more idiomatic to use without changing their implementations or headers. The WebGPU examples show how to import C enums as Swift enums, reference-counted opaque objects as automatically managed classes, and C functions as labeled methods, properties, or initializers. API notes also express ownership and pointer nullability; Swift wrappers can give typedefs distinct types, while OptionSet and Boolean-literal conformance add convenient Swift behavior. The article recommends building a small package to iterate on the imported interface. For regular generated headers like webgpu.h, a Swift script using regular expressions can automate many annotations, though the author calls this a hack and says libclang or the source API database would be better for arbitrary headers. Some covered fixes require Swift 6.2.3.

### Source excerpt

There are many interesting, useful, and fun C libraries in the software ecosystem. While one could go and rewrite these libraries in Swift, usually there is no need, because Swift provides direct interoperability with C. With a little setup, you can directly use existing C libraries from your Swift code. When you use a C library directly from Swift, it will look and feel similar to using it from C. That can be useful if you're following sample code or a tutorial written in C, but it can also feel out of place. For example, here's a small amount of code using a C API: var instanceDescriptor = WGPUInstanceDescriptor() let instance = wgpuCreateInstance(&instanceDescriptor) var surfaceDescriptor = WGPUSurfaceDescriptor() let surface = wgpuInstanceCreateSurface(instance, &surfaceDescriptor) if wgpuSurfacePresent(&surface) == WGPUStatus_Error { // report error } wgpuSurfaceRelease(surface) wgpuInstanceRelease(instance) The C library here that Swift is using comes from the webgpu-headers project, which vends a C header (webgpu.h) that is used by several implementations of WebGPU. WebGPU is a technology that enables web developers to use the system's GPU (Graphics Processing Unit) from the browser. For the purposes of this post, you don't really need to know anything about WebGPU: I'm using it as an example of a typical C library, and the techniques described in this blog post apply to lots of other well-designed C libraries. The Swift code above has a very "C" feel to it. It has global function calls with prefixed names like wgpuInstanceCreateSurface and global integer constants like WGPUStatus_Error. It pervasively uses unsafe pointers, some of which are managed with explicit reference counting, where the user provides calls to wpuXYZAddRef and wgpuXYZRelease functions. It works, but it doesn't feel like Swift, and inherits various safety problems of C. Fortunately, we can improve this situation, providing a safer and more ergonomic interface to WebGPU from Swift that fee

## Fearless Concurrency Ep.6: Understanding Rust ARC for Efficient Multithreading

DevFeed: [Fearless Concurrency Ep.6: Understanding Rust ARC for Efficient Multithreading](<https://devfeed.tech/articles/fearless-concurrency-ep-6-understanding-rust-arc-for-efficient-multithreading-22270.md>)

Original publisher: [Read original article](<https://www.ardanlabs.com/blog/2024/11/fearless-concurrency-ep6-understanding-rust-arc-for-efficient-multithreading.html>)

Published: 2024-11-21T00:00:00Z

Content type: article

Language: en

Sources: [William Kennedy](<https://devfeed.tech/sources/william-kennedy.md>)

Topics: [atomic reference counting](<https://devfeed.tech/topics/atomic-reference-counting.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>), [Rust](<https://devfeed.tech/topics/rust.md>), [multithreading](<https://devfeed.tech/topics/multithreading.md>), [thread safe data sharing](<https://devfeed.tech/topics/thread-safe-data-sharing.md>), [Distributed Systems & Parallel Computing](<https://devfeed.tech/topics/distributed-systems-parallel-computing.md>)

Tags: [applications](<https://devfeed.tech/tags/applications.md>), [arc](<https://devfeed.tech/tags/arc.md>), [arc-best-practices](<https://devfeed.tech/tags/arc-best-practices.md>), [arc-for-performance](<https://devfeed.tech/tags/arc-for-performance.md>), [arc-in-rust](<https://devfeed.tech/tags/arc-in-rust.md>), [arc-memory-management](<https://devfeed.tech/tags/arc-memory-management.md>), [arc-ownership-model](<https://devfeed.tech/tags/arc-ownership-model.md>), [arc-shared-resources](<https://devfeed.tech/tags/arc-shared-resources.md>), [arc-vs-garbage-collection](<https://devfeed.tech/tags/arc-vs-garbage-collection.md>), [arc-with-mutex](<https://devfeed.tech/tags/arc-with-mutex.md>), [arc-with-rwlock](<https://devfeed.tech/tags/arc-with-rwlock.md>), [atomic](<https://devfeed.tech/tags/atomic.md>), [atomic-reference-counting](<https://devfeed.tech/tags/atomic-reference-counting.md>), [best-practices](<https://devfeed.tech/tags/best-practices.md>), [concurrency](<https://devfeed.tech/tags/concurrency.md>), [concurrency-in-rust](<https://devfeed.tech/tags/concurrency-in-rust.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [connection-pool](<https://devfeed.tech/tags/connection-pool.md>), [database](<https://devfeed.tech/tags/database.md>), [efficient-multithreading-rust](<https://devfeed.tech/tags/efficient-multithreading-rust.md>), [garbage-collection](<https://devfeed.tech/tags/garbage-collection.md>), [global](<https://devfeed.tech/tags/global.md>), [heap](<https://devfeed.tech/tags/heap.md>), [implementation](<https://devfeed.tech/tags/implementation.md>), [interior-mutability-arc](<https://devfeed.tech/tags/interior-mutability-arc.md>), [large](<https://devfeed.tech/tags/large.md>), [lightweight](<https://devfeed.tech/tags/lightweight.md>), [lightweight-memory-management](<https://devfeed.tech/tags/lightweight-memory-management.md>), [memory](<https://devfeed.tech/tags/memory.md>), [multithreading](<https://devfeed.tech/tags/multithreading.md>), [multithreading-with-arc](<https://devfeed.tech/tags/multithreading-with-arc.md>), [ownership](<https://devfeed.tech/tags/ownership.md>), [rust](<https://devfeed.tech/tags/rust.md>), [rust-arc-tutorial](<https://devfeed.tech/tags/rust-arc-tutorial.md>), [rust-arc-use-cases](<https://devfeed.tech/tags/rust-arc-use-cases.md>), [rust-concurrency-tools](<https://devfeed.tech/tags/rust-concurrency-tools.md>), [rust-shared-ownership](<https://devfeed.tech/tags/rust-shared-ownership.md>), [rust-thread-safe-programming](<https://devfeed.tech/tags/rust-thread-safe-programming.md>), [thread-safe-data-sharing](<https://devfeed.tech/tags/thread-safe-data-sharing.md>)

### AI overview

Rust ARC shares a heap-allocated value across threads by cloning a pointer and incrementing its reference count; dropping each pointer decrements the count, and the value is destroyed when the count reaches zero. This avoids copying the underlying data and can suit high fan-out sharing, such as sharing configuration or a database connection pool. The excerpt also mentions combining ARC with interior mutability for thread-safe updates and flags circular references as a pitfall. It presents ARC as shared ownership without a traditional garbage collector; the excerpt does not identify the interior-mutability types or give their usage details.

### Source excerpt

Introduction: Welcome to Episode 6 of the Fearless Concurrency in Rust series! In this episode, we explore the powerful concept of ARC (Atomic Reference Counting) and its critical role in managing shared resources in multithreaded Rust programs. By leveraging ARC, developers can safely share ownership of data across threads without relying on a traditional garbage collector, enabling efficient, flexible, and scalable concurrency. What is ARC?: Understanding Atomic Reference Counting as a lightweight, manual garbage collection system.

## Friday Q&A 2017-09-22: Swift 4 Weak References

DevFeed: [Friday Q&A 2017-09-22: Swift 4 Weak References](<https://devfeed.tech/articles/friday-q-a-2017-09-22-swift-4-weak-references-30622.md>)

Original publisher: [Read original article](<http://www.mikeash.com/pyblog/friday-qa-2017-09-22-swift-4-weak-references.html>)

Author: Mike Ash

Published: 2017-09-23T00:57:00Z

Content type: article

Language: en

Sources: [Mike Ash](<https://devfeed.tech/sources/mike-ash.md>)

Topics: [Swift](<https://devfeed.tech/topics/swift.md>), [atomic reference counting](<https://devfeed.tech/topics/atomic-reference-counting.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>)

Tags: [friday](<https://devfeed.tech/tags/friday.md>), [swift](<https://devfeed.tech/tags/swift.md>)

### AI overview

Swift's optional side tables address two flaws in its earlier weak-reference design: zombie objects could retain large allocations until weak references were accessed, and concurrent reads were not thread-safe. Previously, weak references pointed to the object itself; after its strong count reached zero, the destroyed object remained in memory until weak references were loaded and cleared. Now, an object needing weak references gets a small side table, and weak references point to that table. This keeps large object memory from being retained and lets weak references remain untouched until overwritten or destroyed. The object's reference-count word becomes a side-table pointer, with a bit distinguishing the two; reference counts move into the table. The article says the current table holds reference counts and a pointer to the object. Using it for associated objects is described as a possibility, while Objective-C associated objects still use a global table.

### Source excerpt

Soon after Swift was initially open sourced, I wrote an article about how weak references are implemented. Time moves on and things change, and the implementation is different from what it once was. Today I'm going to talk about the current implementation and how it works compared to the old one, a topic suggested by Guillaume Lessard. (Read More)

## Friday Q&A 2017-08-11: Swift.Unmanaged

DevFeed: [Friday Q&A 2017-08-11: Swift.Unmanaged](<https://devfeed.tech/articles/friday-q-a-2017-08-11-swift-unmanaged-30620.md>)

Original publisher: [Read original article](<http://www.mikeash.com/pyblog/friday-qa-2017-08-11-swiftunmanaged.html>)

Author: Mike Ash

Published: 2017-08-11T13:14:00Z

Content type: article

Language: en

Sources: [Mike Ash](<https://devfeed.tech/sources/mike-ash.md>)

Topics: [Swift](<https://devfeed.tech/topics/swift.md>), [atomic reference counting](<https://devfeed.tech/topics/atomic-reference-counting.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [apis](<https://devfeed.tech/tags/apis.md>), [arc](<https://devfeed.tech/tags/arc.md>), [arc-memory-management](<https://devfeed.tech/tags/arc-memory-management.md>), [asynchronous](<https://devfeed.tech/tags/asynchronous.md>), [bridging](<https://devfeed.tech/tags/bridging.md>), [c](<https://devfeed.tech/tags/c.md>), [callback](<https://devfeed.tech/tags/callback.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [context](<https://devfeed.tech/tags/context.md>), [dns](<https://devfeed.tech/tags/dns.md>), [generic](<https://devfeed.tech/tags/generic.md>), [object](<https://devfeed.tech/tags/object.md>), [object-references](<https://devfeed.tech/tags/object-references.md>), [pointers](<https://devfeed.tech/tags/pointers.md>), [struct](<https://devfeed.tech/tags/struct.md>), [swift](<https://devfeed.tech/tags/swift.md>)

### AI overview

Swift's `Unmanaged` bridges object references and raw `void *` pointers while leaving ARC ownership decisions to the programmer. For Swift-to-C transfer, `passRetained` gives C an owned reference that must later be balanced; `passUnretained` adds no ownership and is safe only when the object remains alive or C takes ownership. Convert the wrapper with `toOpaque`. On return to Swift, use `fromOpaque` with the expected type, then `takeRetainedValue` to balance an owned reference or `takeUnretainedValue` without changing ownership. For callbacks, the article recommends unretained passing for synchronous calls, retained passing and release in a one-shot callback, and retaining across multi-shot callbacks until a separate destruction callback releases it. It cautions against `unsafeBitCast` for pointer conversion and notes that incorrect ownership can cause leaks, premature deallocation, or crashes.

### Source excerpt

In order to work with C APIs, we sometimes need to convert Swift object references to and from raw pointers. Swift's Unmanaged struct is the standard API for handling this. Today, I'd like to talk about what it does and how to use it. (Read More)