Repository navigation
Description
Since #792 (merged in #804), Datadeps no longer frees the copies it makes of NoAliasing arguments when a region ends. The copies stay allocated until garbage collection reclaims them, which can take a long time for device memory or for buffers on remote workers or MPI ranks.
What happens
#792 added an early return to aliased_object! so that distinct NoAliasing values no longer share one cached slot (src/datadeps/aliasing.jl):
(ainfo isa NoAliasing || (ainfo isa AliasingWrapper && ainfo.inner isa NoAliasing)) && return f(x)::ChunkWhen the argument has to move to another memory space, f(x) makes a new chunk there (move_rewrap → tochunk(libc_backed(move(...)), to_proc, to_space)). Because of the early return, that copy is never recorded in the aliased-object cache.
At the end of a region, Datadeps frees the copies it made by walking the cache (src/datadeps/queue.jl, the loop over obj_cache.values that spawns unsafe_free! for every non-original entry). A copy that never entered the cache is never freed there.
Before #792, the first NoAliasing copy was cached (wrongly shared with later values, which was the bug #792 fixed) and was freed at region end. So this lifetime change came with #792. It is not pre-existing.
Related: one identity-less case still collides
The default aliasing(x::T) skips NoAliasing fields. For a struct whose only aliasing-relevant fields are NoAliasing, it returns an empty CombinedAliasing, and all empty CombinedAliasing values compare and hash equal (src/memory-spaces.jl). Given #792's test type NoAliasVal, a wrapper such as struct Outer; x::NoAliasVal; end still passes type_may_alias and still hits one shared cache key. A distinct Outer argument can therefore still receive another one's slot.
Possible fix
Both cases come from using the aliasing value as the cache key when it carries no identity. Keying such values by object identity (or giving AbstractAliasing a dispatchable "has no identity" predicate, which an empty memory_spans also satisfies) would keep each value's slot separate and register the copy, so region teardown frees it again. It would also cover user-defined identity-less aliasing types.
How this was found
By reading the code during a review of #792; not yet reproduced by running it. A reproducer would move two distinct NoAliasing values across memory spaces in one spawn_datadeps region (for example to a second Distributed worker or a GPU) and check that their destination chunks are freed when the region ends.
Activity
jpsamaroo commentedon Nov 28, 2026
Correction on scope: this matters less widely than the description implies.
Datadeps' region-end free is
unsafe_free!(chunk), which unwraps the chunk and frees the value only if it is a type Dagger knows how to release (src/memory-spaces.jl):Arraywith anisbitselement type (Datadeps'move_rewrapcopies these into Libc-backed memory vialibc_backed, so they can be freed eagerly);CuArray,ROCArray,MtlArray,oneArray,CLArray, through the GPU extensions).For every other value,
unsafe_free!(x) = nothing. That includes a struct like #792's test typeNoAliasVal(a struct holding aVector), so for such values nothing was ever freed eagerly, before or after #792.So the lost eager free affects only users who declare
aliasing(...) = NoAliasing()on an isbits-elementArraytype or a GPU array type, for exampleDagger.aliasing(::Vector{TileOut}) = Dagger.NoAliasing()with an isbitsTileOut. For those, cross-space copies now wait for GC; for everything else this part of the issue changes nothing. The second point (an emptyCombinedAliasingstill sharing one slot) is about correctness, not memory, and stands as written.AnnaLena77 commentedon Nov 28, 2026
Thanks for the careful read, and you are right on both points: the lost eager free is a regression from #792, and the empty
CombinedAliasingcase still shares one slot.One thing that may help with the scope: the case in your correction,
Dagger.aliasing(::Vector{TileOut}) = Dagger.NoAliasing()with an isbitsTileOut, is exactly what one of our applications does, so we do hit it (the copies of those tile vectors now wait for GC).I opened #833, which keys such values by identity and registers the copy, so that the region teardown frees it again and distinct identity-less values (including the
Outerwrapper) keep separate slots. It comes with a test that moves distinctNoAliasingvalues andOuterwrappers to another worker and checks that each task sees its own value and that all copies are freed when the region ends.Datadeps: free copies of identity-less arguments, give each its own slot