Uh oh!
There was an error while loading. Please reload this page.
Deduplicate "all managed object wrappers" mapping - #133260
Conversation
Prevent duplicate entries in the "all managed object wrappers" table. Fixes#129191 For the case in #129191, there is always only one ComWrappers instance, so this collection will be length 1. I chose to do a simple fix like this for the following reasons: 1. This collection is read from the DAC and cDAC directly to support the `!DumpObj` command. Any significant changes to the structure (such as moving to a `HashSet<ManagedObjectWrapperHolder>`) would require very large changes to enable enumerating the structure from DAC or cDAC code, creating a higher risk change for backporting. 2. In practice, objects are passed to unmanaged code via 1 ComWrappers instance in the vast majority of cases outside of our own tests. In the unlikely case it's passed via more than 1, it would be via 2, the CsWinRT ComWrappers instance and the StrategyBasedComWrappers default instance. 3. I considered adding a parallel HashSet for deduplication. However, that felt like a very large memory cost for the common scenario (.NET object passed to native via only one ComWrappers instance) for a minor savings in a very unlikely scenario (many ComWrappers for the same .NET object).
Tagging subscribers to this area: @dotnet/area-system-runtime |
|
Azure Pipelines: Successfully started running 2 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The change is small, localized to diagnostics registration, and avoids unbounded list growth while keeping the existing DAC/cDAC-observable structure intact.
Review tier: Lite
Findings: None
What changed in this PR
Prevents duplicate ManagedObjectWrapperHolder entries from being recorded in the global “all managed object wrappers” ConditionalWeakTable, which is used by diagnostics tooling to enumerate managed object wrappers.
Changes:
- Adds a guarded insert (
Containscheck) when registering a managed object wrapper for diagnostics, preventing repeated additions of the sameManagedObjectWrapperHolderto the per-object list.
| File | Description |
|---|---|
| src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/ComWrappers.cs | Deduplicates per-object wrapper registration in the diagnostics tracking table to avoid list growth from repeated registrations. |
Uh oh!
There was an error while loading. Please reload this page.
jkoritzinsky
commented
Sep 5, 2026
/backport to release/10.0 |
jkoritzinsky
commented
Sep 5, 2026
/backport to release/11.0 |
Started backporting to |
Started backporting to |
Prevent duplicate entries in the "all managed object wrappers" table.
Fixes#129191
For the case in #129191, there is always only one ComWrappers instance, so this collection will be length 1.
I chose to do a simple fix like this for the following reasons:
!DumpObjcommand. Any significant changes to the structure (such as moving to aHashSet<ManagedObjectWrapperHolder>) would require very large changes to enable enumerating the structure from DAC or cDAC code, creating a higher risk change for backporting.