Skip to content

Commit

Permalink
Fix JNI array leaking by freeing the memory after conversion (#167)
Browse files Browse the repository at this point in the history
Co-authored-by: Stefan Tanja <[email protected]>
  • Loading branch information
satanja and Stefan Tanja authored Jul 18, 2023
1 parent 63026e4 commit d7f3136
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/convert.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ function convert_result(rettype::Type{Array{JavaObject{T},1}}, result) where T
a=JNI.GetObjectArrayElement(result, i-1)
ret[i] = JavaObject{T}(a)
end

JNI.DeleteLocalRef(result)
return ret
end

Expand All @@ -169,6 +171,8 @@ function convert_result(rettype::Type{Array{T,1}}, result) where T
a=JNI.GetObjectArrayElement(result, i-1)
ret[i] = convert_result(T, a)
end

JNI.DeleteLocalRef(result)
return ret
end

Expand All @@ -191,6 +195,8 @@ function convert_result(rettype::Type{Array{JavaObject{T},2}}, result) where T
ret[i, j] = JavaObject{T}(x)
end
end

JNI.DeleteLocalRef(result)
return ret
end

Expand All @@ -211,6 +217,8 @@ function convert_result(rettype::Type{Array{T,2}}, result) where T
@assert(sz_a == sz_1, "Size of $(i)th subrarray is $sz_a, but size of the 1st subarray was $sz_1")
ret[i, :] = convert_result(Vector{T}, a)
end

JNI.DeleteLocalRef(result)
return ret
end

Expand Down

0 comments on commit d7f3136

Please sign in to comment.