Skip to content

Commit 4365e01

Browse files
committed
fix leak
1 parent 1b7c406 commit 4365e01

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/abstractgbarray.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,21 @@ function Base.copyto!(C::AbstractGBArray, A::GBArrayOrTranspose)
4343
end
4444

4545
function Base.Matrix(A::GBArrayOrTranspose)
46-
T = copy(A) # We copy here to 1. avoid densifying A, and 2. to avoid destroying A.
47-
return unsafeunpack!(T, Dense())
46+
format = sparsitystatus(A)
47+
if format === Dense()
48+
T = unsafeunpack!(A, Dense())
49+
M = copy(T)
50+
unsafepack!(A, T, false)
51+
else
52+
# if A is not dense we end up doing 2x copies. Once to avoid densifying A.
53+
T = copy(A)
54+
U = unsafeunpack!(T, Dense())
55+
# And again to make this a native Julia Array.
56+
# if we didn't copy here a user could not resize
57+
M = copy(U)
58+
unsafepack!(T, U, false)
59+
end
60+
return M
4861
end
4962

5063
function Base.Vector(A::GBVectorOrTranspose)
@@ -62,7 +75,7 @@ function Base.Vector(A::GBVectorOrTranspose)
6275
M = copy(U)
6376
unsafepack!(T, U, false)
6477
end
65-
M
78+
return M
6679
end
6780

6881
function SparseArrays.SparseMatrixCSC(A::GBArrayOrTranspose)

0 commit comments

Comments
 (0)