Skip to content

Commit d7f3136

Browse files
satanjaStefan Tanja
and
Stefan Tanja
authored
Fix JNI array leaking by freeing the memory after conversion (#167)
Co-authored-by: Stefan Tanja <[email protected]>
1 parent 63026e4 commit d7f3136

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Diff for: src/convert.jl

+8
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ function convert_result(rettype::Type{Array{JavaObject{T},1}}, result) where T
155155
a=JNI.GetObjectArrayElement(result, i-1)
156156
ret[i] = JavaObject{T}(a)
157157
end
158+
159+
JNI.DeleteLocalRef(result)
158160
return ret
159161
end
160162

@@ -169,6 +171,8 @@ function convert_result(rettype::Type{Array{T,1}}, result) where T
169171
a=JNI.GetObjectArrayElement(result, i-1)
170172
ret[i] = convert_result(T, a)
171173
end
174+
175+
JNI.DeleteLocalRef(result)
172176
return ret
173177
end
174178

@@ -191,6 +195,8 @@ function convert_result(rettype::Type{Array{JavaObject{T},2}}, result) where T
191195
ret[i, j] = JavaObject{T}(x)
192196
end
193197
end
198+
199+
JNI.DeleteLocalRef(result)
194200
return ret
195201
end
196202

@@ -211,6 +217,8 @@ function convert_result(rettype::Type{Array{T,2}}, result) where T
211217
@assert(sz_a == sz_1, "Size of $(i)th subrarray is $sz_a, but size of the 1st subarray was $sz_1")
212218
ret[i, :] = convert_result(Vector{T}, a)
213219
end
220+
221+
JNI.DeleteLocalRef(result)
214222
return ret
215223
end
216224

0 commit comments

Comments
 (0)