Skip to content

In Java bindings, delete more local references#589

Closed
jtraglia wants to merge 1 commit intoethereum:mainfrom
jtraglia:java-delete-local-refs
Closed

In Java bindings, delete more local references#589
jtraglia wants to merge 1 commit intoethereum:mainfrom
jtraglia:java-delete-local-refs

Conversation

@jtraglia
Copy link
Member

Teku shared with me that their memory usage with ckzg is higher than expected (~10gb). I believe the issue is that we were not properly deleting local references.

@asn-d6
Copy link
Contributor

asn-d6 commented Aug 1, 2025

Changes look sensible, but a bit hard to review due to the error cases that need to be handled.

What do you think about trying out a goto-based free strategy, like we do in the core library code?
The calls to DeleteLocalRef in the functions that can throw errors get quite complicated.
IIUC we could implement goto-based freeing since the docs say that localRef: a local reference. The function does nothing in the case of a NULL value passed here..

Also, have we tested that these changes fix the memleaks? Should we get a Teku devs to do some testing?

@tbenr
Copy link
Contributor

tbenr commented Aug 1, 2025

I spent some time on this and I don't think those changes matter than much. We are not facing a memory leak issue here.

the relevant reading is this: https://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/design.html#wp1242

I don't think we fall into the situation in which is better to manually call DeleteLocalRef.

As per doc:
Local references are valid for the duration of a native method call, and are automatically freed after the native method returns.
This should be good enough for us.

@jtraglia jtraglia closed this Aug 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants