Skip to content

Conversation

@halibobo1205
Copy link
Contributor

@halibobo1205 halibobo1205 commented Oct 24, 2025

What does this PR do?

This PR improves native memory management in RocksDB operations by properly closing WriteOptions and ReadOptions objects using try-with-resources statements.

Why are these changes required?

RocksDB Java objects like WriteOptions, ReadOptions, Options, and RocksIterator wrap native C++ objects and hold off-heap memory that is not managed by the JVM garbage collector. According to the RocksJava Basics - Memory Management documentation:

"Many of the Java Objects used in RocksJava will free their associated C++ objects when they are garbage collected via their finalize() method; however, this may take some time to occur. To speed this up it is best to explicitly call the close() method (or use try-with-resources) of any objects which implement java.lang.AutoCloseable."

This PR has been tested by:

  • Unit Tests
  • Manual Testing

Follow up

Extra details

1. Test

image image
Code Version Architecture JDK GC DB Memory Used
Leak arm64 8 G1GC rocksDB Stable leak
Fixed arm64 8 G1GC rocksDB No leak, stable 2G
Leak x86 8 G1GC rocksDB No leak, stable 3G
Fixed x86 8 G1GC rocksDB No leak, stable 3G
Leak arm64 17 G1GC rocksDB Stable leak
Fixed arm64 17 G1GC rocksDB No leak, stable 3G
Leak x86 17 G1GC rocksDB No leak, stable 3G
Fixed x86 17 G1GC rocksDB No leak, stable 3G
Leak arm64 17 ZGC rocksDB Stable leak
Fixed arm64 17 ZGC rocksDB No leak, stable 830M
Leak x86 17 ZGC rocksDB No leak, stable 900M
Fixed x86 17 ZGC rocksDB No leak, stable 920M

Summary

  • Memory leak issue is specific to arm64 architecture: All unfixed versions on arm64 exhibit stable memory leaks, regardless of JDK version (8 or 17) or GC type (G1GC or ZGC)
  • x86 architecture shows no memory leaks: Both unfixed and fixed versions on x86 maintain stable memory usage without leaks
  • The fix resolves arm64 memory leaks: After applying the fix, arm64 systems stabilize at consistent memory levels
  • ZGC shows better memory efficiency: On both architectures with JDK 17, ZGC uses significantly less memory (~830-920M) compared to G1GC (~3G)
  • The issue appears to be an arm64-specific bug: The problem is isolated to the arm64 platform and is successfully resolved by the code fix

2. reference linking

@halibobo1205 halibobo1205 force-pushed the feat/rocksdb_opt branch 2 times, most recently from 63aeed9 to 9be6c52 Compare October 24, 2025 09:06
@halibobo1205 halibobo1205 force-pushed the feat/rocksdb_opt branch 2 times, most recently from 4ab3faf to ae451fe Compare October 28, 2025 08:23
Copy link
Contributor

@waynercheung waynercheung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kuny0707 kuny0707 merged commit a4fbb0c into tronprotocol:release_v4.8.1 Oct 29, 2025
7 checks passed
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.

6 participants