Skip to content

docs(util): clarify Accountable.ramBytesUsed() ownership semantics#16114

Draft
salvatorecampagna wants to merge 2 commits into
apache:mainfrom
salvatorecampagna:docs/accountable-ownership
Draft

docs(util): clarify Accountable.ramBytesUsed() ownership semantics#16114
salvatorecampagna wants to merge 2 commits into
apache:mainfrom
salvatorecampagna:docs/accountable-ownership

Conversation

@salvatorecampagna
Copy link
Copy Markdown
Contributor

@salvatorecampagna salvatorecampagna commented May 23, 2026

TL;DR

Documentation only PR. Clarifies the ownership convention for Accountable.ramBytesUsed() and notes that getChildResources() is a diagnostic accessor, not a deduplicated ownership tree. No behavior change.

Summary

Accountable.ramBytesUsed() is currently documented as "an estimate of the bytes used by this object" without saying whether bytes from referenced objects are included. Implementations vary: some count everything reachable, others count only owned state. When external code sums ramBytesUsed() across multiple Accountable instances that share state, the same memory can be counted more than once.

This PR adds an ownership-oriented convention to the javadoc:

  • Report memory allocated for the object's lifetime, or released by its close() if applicable.
  • Inputs received via constructors or factories may be borrowed, wrapped, sliced, or copied. Report only the bytes actually owned, not the deep content of referenced storage that is not owned.
  • The reference itself (the pointer slot for a borrowed field) is part of the holder's own object layout and is naturally accounted via shallow size.
  • getChildResources() is diagnostic; summing ramBytesUsed() across its elements is not generally sum-safe.

The convention is already followed informally in parts of the codebase. This PR documents it so future implementers and reviewers have a clear contract to apply.

Changes

  • Accountable.java: extended javadoc on ramBytesUsed() with the ownership convention; extended javadoc on getChildResources() to note it is a diagnostic accessor and not sum-safe.

Refs #16113.

Document an ownership-oriented convention for Accountable implementations:
report memory allocated for the object's lifetime, or released by its
close() if applicable. Inputs received via constructors or factories may
be borrowed, wrapped, sliced, or copied; implementations should report
only the bytes they actually own, not the deep content of referenced
storage they do not own.

Also clarify that getChildResources() is a diagnostic accessor and not a
deduplicated ownership tree: summing ramBytesUsed() across its elements
is not generally sum-safe.

Refs apache#16113.
The Lucene PR workflow requires a CHANGES.txt entry. Added under
Lucene 10.5.0 -> Other since the change is documentation only and not
breaking.

Refs apache#16113, apache#16114.
@github-actions github-actions Bot added this to the 10.5.0 milestone May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants