Weird crash in Swift "Object of class _ContiguousArrayStorage deallocated with non-zero retain count 2."
I had some old code which tries to protect its internal state using a DispatchQueue. But it's a struct.
When I access it from multiple threads at the same time via a class, it crashes. In my old Swift 5 code I didn't have the "unchecked Sendable", and I assumed it was correct because of the DispatchQueue.
My actual fix is changing the struct to a final class.
@tomlokhorst hmm do you understand why?

@mattiem Not fully. The mutating func is modifying the buffer var in the class simultaneously. But I don't know why this triggers this particular crash, at this location.

It also depends on the OS version, on macOS 26 it's the new xzone malloc, but on macOS 15 it sometimes fails with "Fatal error: UnsafeMutablePointer.initialize overlapping range".

https://github.com/nonstrict-hq/StructQueueCrash

@tomlokhorst (cannot see that repo, public?)

The concurrent queue + barrier immediately stands out to me. Have you tried a serial queue?

@mattiem Now it’s public.
I think serial queue has same issue. The concurrent queue was just there because that was in my original code.