Skip to content

Conversation

github-actions[bot]
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.

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.

1 participant