-
-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible memory leak in convert_result
#134
Comments
The My thought is that we should probably use something like On this specific question, it seems strange that this is the only case when Perhaps what we need is a function convert_result!(rettype, result)
converted_result = convert_result(rettype, result)
JNI.DeleteLocalRef(result)
return converted_result
end By default we call Another question is are we sure that In summary, I suspect a larger fix is needed. In the meantime, I would be willing to accept your pull request. |
Regarding |
I think the above use of It would allow some degree of functionality like with NumPy arrays via PyCall.jl that I'm trying to expand: |
Yes, I was glad to see that this was exposed in a useful way, and creating convenience wrappers like
I guess it's fine when the returned ref is just wrapped in a convert_result!(rettype::Type{T}, result) where {T<:JavaObject} = T(result)
I like this idea, makes a lot of sense to me! I'll probably experiment with it a bit for the BioFormats use-case. |
BioformatsLoader.jl has had some problems with OOM-errors. I just added a workaround using local frames (ahnlabb/BioformatsLoader.jl@4d4e2d5). However, it seems like this could be a bigger issue with the
result
variable inconvert_result
, it is unclear to me when that local reference is deleted (it is not made into a JavaObject and does not have the deleteref finalizer) and the memory leak issues in BioformatsLoader.jl are fixed if an explicitJNI.DeleteLocalRef(result)
is added as in ahnlabb/JavaCall.jl@94289c5 (potentially relevant SO question).If you think this is indeed the correct approach I can open a PR from ahnlabb/JavaCall.jl@94289c5.
As an aside, BioformatsLoader could possibly benefit from increased control over the byte array life cycle and passing raw
byte[]
references to Java (as is discussed in #83).The text was updated successfully, but these errors were encountered: