Skip to content

Make ByteBuddy handler instance-scoped to prevent leaks#773

Merged
chhsiao90 merged 1 commit intomodelmapper:masterfrom
amodolo:master
Sep 30, 2025
Merged

Make ByteBuddy handler instance-scoped to prevent leaks#773
chhsiao90 merged 1 commit intomodelmapper:masterfrom
amodolo:master

Conversation

@amodolo
Copy link
Copy Markdown
Contributor

@amodolo amodolo commented Sep 10, 2025

Move from class-scoped to instance-scoped InvocationHandler in generated proxies:

  • Define a private field $mmHandler on the proxy class and route calls via InvocationHandlerAdapter.toField("$mmHandler") instead of InvocationHandlerAdapter.of(...).
  • After creating the proxy instance (Objenesis), set the field reflectively.

This prevents the proxy class from holding a class-level reference to the handler, which previously retained ExplicitMappingBuilder and InheritingConfiguration captured by the handler.
In issue #375-like scenarios, this reduces retained heap and avoids long-lived retention without changing behavior.

@chhsiao90
Copy link
Copy Markdown
Member

Thanks, LGTM

@chhsiao90 chhsiao90 merged commit 5e3b35e into modelmapper:master Sep 30, 2025
4 checks passed
@chhsiao90
Copy link
Copy Markdown
Member

Just released 3.2.5, it should be available soon from the maven central.

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.

2 participants