Skip to content

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Sep 22, 2025

Backport of #119749 to release/10.0

/cc @BrzVlad

Customer Impact

  • Customer reported
  • Found internally

Dynamic methods leak even after they are collected / no longer used.

Regression

  • Yes
  • No

Testing

This was tested on applications making use of system reflection emit.

Risk

Low. This just frees various runtime data that is no longer used.

Ever since the early days of mono, freeing dynamic methods was disabled if a profiler was attached. The reason for this was probably that the profiler might store `MonoMethod` instances in its own data, leading to problems if we free those instances. Looking at the profilers nowadays it is not clear where patterns like this would happen. Profilers that do store methods (like aot, coverage), don't process wrapper methods, so we should be safe since dynamic methods have the MONO_WRAPPER_DYNAMIC_METHOD wrapper type.

The problem is that, nowadays, we can always have a profiler attached even if no actual profiling happens. macios for example always calls mono_profiler_install. I belive actual callbacks can be added later as necessary.
@BrzVlad BrzVlad marked this pull request as draft September 22, 2025 15:13
@BrzVlad
Copy link
Member

BrzVlad commented Sep 22, 2025

I believe it would make more sense to backport this together with fixes on the interpreter side that add freeing of interpreter data. I need to do some more investigations on that front so this will miss RC2.

@steveisok steveisok added the Servicing-consider Issue for next servicing release review label Oct 6, 2025
@dotnet-policy-service
Copy link
Contributor

Tagging subscribers to this area: @steveisok, @vitek-karas
See info in area-owners.md if you want to be subscribed.

@rbhanda rbhanda added this to the 10.0.0 milestone Oct 7, 2025
@rbhanda rbhanda added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Oct 7, 2025
@BrzVlad BrzVlad closed this Oct 7, 2025
@BrzVlad
Copy link
Member

BrzVlad commented Oct 7, 2025

@steveisok This PR was a draft. I needed to add a couple more commits to it so it is complete. Closed it so no confusions happen.

@stephentoub stephentoub deleted the backport/pr-119749-to-release/10.0 branch October 17, 2025 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Codegen-meta-mono Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants