Closed emetsds closed 4 years ago
I think the references are being handled correctly in CallMethod
, you could try using https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#EnsureLocalCapacity and/or make sure you are deleting references. There are methods in JNIGI to do this.
Sorry for my english, it's a bit hard for me to explain, but I can provide simple test that produces the memory leak. And this can be fixed by my pull request. This test consist of java method that returns empty byte array and go method that infinitely calls this method. If you call this test, it will crash in about 10 seconds. Because CallMethod
returns me a go array, I can`t delete local reference manually
localRefLeak.zip
Ahh ok thanks yes the reference to the array is leaked. Thanks 👍 I will look at the PR tomorrow.
🎉 Great! thanks for finding that, explaining the problem and fixing.
I get this warning all the time
WARNING: JNI local refs: 363, exceeds capacity: 362
when trying to use methods that return an object It seems that local references to the returned values are not deleted. This small fix avoids the warning, but I'm not sure it's completely correct. Please take a look at this