evmc icon indicating copy to clipboard operation
evmc copied to clipboard

java: clean up memory handling

Open axic opened this issue 5 years ago • 3 comments

Apparently the bindings should be leaking a lot of memory because references are never released, see https://www.ibm.com/support/knowledgecenter/en/SSYKE2_8.0.0/com.ibm.java.vm.80.doc/docs/jni_refs.html and https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/functions.html#Release_PrimitiveType_ArrayElements_routines

axic avatar Sep 29 '20 22:09 axic

I ran the VM reference tests against the EVM in a continuous loop for several hours and didn't notice a leak. It's cool to dispose of memory explicitly. I believe the JVM disposes of ByteBuffer objects it creates through garbage collection otherwise.

atoulme avatar Sep 30 '20 18:09 atoulme

I ran the VM reference tests against the EVM in a continuous loop for several hours and didn't notice a leak. It's cool to dispose of memory explicitly. I believe the JVM disposes of ByteBuffer objects it creates through garbage collection otherwise.

My impression from the documentation was that these objects are part of garbage collection, but owned by the JNI interface, hence they need to be freed. They are not large objects however, so I can imagine it can lasts days before OOM.

Can you point me to the documentation where this is clarified?

Also note some of the memory freeing is already part of the code, it is inconsistent.

axic avatar Oct 08 '20 22:10 axic

OK, I think I'm wrong here. You're right, let's dispose of memory explicitly.

atoulme avatar Oct 09 '20 07:10 atoulme