On 8/17/2026 4:59 PM, Dan Smith wrote:
On Aug 17, 2026, at 3:04 PM, Kevin Rushforth <[email protected]> wrote:

That's an interesting question. And one I'll need to drill into when I get to the WebView Java <--> JS bridge implementation. Up until now, I've been assuming that we don't care much about whether value objects leak. For small objects like the boxed primitive classes, that seems a reasonable assumption (what does it mean to "leak" an integer?). However, if a user-defined value object (e.g., a simple value record) contains a large array of integers or a reference to a user-defined identity object, then I think we do care.

Right. I think there are three kinds of value objects worth keeping in mind:
- Small primitive data wrappers (the common case)
- Wrappers around identity pointers (including large strings and arrays, totally reasonable in certain contexts)
- Large identity-free trees of value objects (discouraged)

Yes, that seems like a useful distinction.

Brian talked about holding onto the first category forever, while releasing the second category once the identity object is otherwise unreachable. That would probably be an acceptable outcome in practice, although it leaves the potential for significant memory leaks caused by the third category. But maybe the third category is a “shoot yourself in the foot” situation.

On the other hand, if we take seriously the risk of memory leaks caused by value objects, I’m not sure there’s any acceptable solution: a value object that gets pinned forever can cause memory leaks, while a value object that can get released at any future moment, possibly even immediately, cannot be reliably cached—might as well just be left out completely.


For WebView's JS bridge case we will need to document this limitation. Based on the current JEP-401 spec / behavior, the warning will need to cover both the second and third categories. I will likely call out Optional specifically, given that it is an existing class that becomes an identity class, but the general advice will apply to any value class.

-- Kevin

Reply via email to