-
Notifications
You must be signed in to change notification settings - Fork 154
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
Memory leaks in methods looking up Class objects #109
Comments
Benchmark `call_static_method` with extra Push/PopLocalFrame ensuring there are no leaks. See jni-rs#109
If the native method implementation deals with large arrays of objects, then it might run out of local references storage sooner.
From a library user perspective, it is reasonable to assume this.
Also likely to consume more memory due to the additional local references stacks created. |
…now `!Copy`. Note that it is now sometimes necessary to use turbofish syntax with `Desc::lookup`, since the return type of `Desc::<T>::lookup` is not necessarily `T` any more (it might be `&T` or something instead). For example, if you need a `JThrowable` and the compiler can't figure that out, write `Desc::<JThrowable>::lookup(input, env)` instead of `input.lookup(env)`. User code doesn't usually use `Desc` directly, so this shouldn't be too much of a problem. This new design has the side benefit that looked-up values can be wrapped in `AutoLocal`, which fixes jni-rs#109.
…#392). Fix local reference leaks (jni-rs#109). Extensive breaking API changes (see changelog). Closes jni-rs#392. Closes jni-rs#381. Closes jni-rs#109. See jni-rs#392 for the discussion that led to this commit.
…#392). Fix local reference leaks (jni-rs#109). Extensive breaking API changes (see changelog). Closes jni-rs#392. Closes jni-rs#381. Closes jni-rs#109. See jni-rs#392 for the discussion that led to this commit.
…#392). Fix local reference leaks (jni-rs#109). Extensive breaking API changes (see changelog). See jni-rs#392 for the discussion that led to this commit. Closes jni-rs#392 Closes jni-rs#381 Closes jni-rs#109 Co-authored-by: Robert Bragg <robert@sixbynine.org>
…#392). Fix local reference leaks (jni-rs#109). Extensive breaking API changes (see changelog). See jni-rs#392 for the discussion that led to this commit. Closes jni-rs#392 Closes jni-rs#381 Closes jni-rs#109 Co-authored-by: Robert Bragg <robert@sixbynine.org>
Overview
JNIEnv
methods acceptingDesc<JClass>
leak a local reference to the Class object if they create a new local reference.Description
If an implementation of
Desc#lookup
that creates a new local reference is passed to theJNIEnv
methods, the created local reference will be leaked (resulting in a leak of native JVM heap and a (potential) leak of referenced Java object). E.g.,will leak a single local reference to an instance of
Class<java.lang.Math>
created here each time it is called.There are about two dozens of
Desc#lookup
s in the codebase.Which client code is NOT affected (benign leaks)
Such leaks can be considered benign if all created local references are freed later:
with_local_frame
— freed after the last statement in that lambda.Which client code IS affected
Code using affected methods in:
with_local_frame
/auto_local
to manage the references created by the user, it must be noted that it's not required if it performs only simple calls that do not expose any references that have to be deleted. In other words, it is reasonable to expect that the library methods do not leak — and that's the specified behaviour of the C APIs:How to reproduce
See #108
Possible solutions
See Also
The text was updated successfully, but these errors were encountered: