GPUArrays.jl icon indicating copy to clipboard operation
GPUArrays.jl copied to clipboard

Fix resize! for JLVector

Open jipolanco opened this issue 1 year ago • 3 comments

This fixes a reference counting issue when using resize! on a JLVector.

The issue is illustrated by the following example:

using JLArrays

u = JLArray{Float64}(undef, 0)
data_prev = u.data
resize!(u, 16)
data = u.data

GC.gc()
data_prev.rc.count[]  # should be 0 (old data was freed)
data.rc.count[]       # should be 1 (new data is still available)

Without this PR, the last two lines incorrectly give 1 and 0 when it should be the opposite.

This means in particular that doing things like copy(u) after resize! failed with ArgumentError: Attempt to use a freed reference..

jipolanco avatar Jun 28 '24 11:06 jipolanco