Skip to content

Commit b4431db

Browse files
committed
[embedded] Add a more detailed explaining comment to swift_release_n_
1 parent c8cbf06 commit b4431db

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

stdlib/public/core/EmbeddedRuntime.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,14 @@ func swift_release_n_(object: UnsafeMutablePointer<HeapObject>?, n: UInt32) {
292292
let resultingRefcount = subFetchAcquireRelease(refcount, n: Int(n)) & HeapObject.refcountMask
293293
if resultingRefcount == 0 {
294294
// Set the refcount to immortalRefCount before calling the object destroyer
295-
// to prevent future retains/releases from having any effect.
295+
// to prevent future retains/releases from having any effect. Unlike the
296+
// full Swift runtime, we don't track the refcount inside deinit, so we
297+
// won't be able to detect escapes or over-releases of `self` in deinit. We
298+
// might want to reconsider that in the future.
299+
//
300+
// There can only be one thread with a reference at this point (because
301+
// we're releasing the last existing reference), so a relaxed store is
302+
// enough.
296303
storeRelaxed(refcount, newValue: HeapObject.immortalRefCount)
297304

298305
_swift_embedded_invoke_heap_object_destroy(object)

0 commit comments

Comments
 (0)