Skip to content

[NSObject] Store the super handle in a ConditionalWeakTable. - #25454

Merged
rolfbjarne merged 6 commits into
mainfrom
dev/rolf/superhandle-in-conditionalweaktable
May 22, 2026
Merged

rolfbjarne merged 6 commits into
mainfrom
dev/rolf/superhandle-in-conditionalweaktable

Conversation

@rolfbjarne

@rolfbjarne rolfbjarne commented May 18, 2026 •

Copy link
Copy Markdown
Member

Store the super handle in a ConditionalWeakTable.

  • Allocate native memory for it.
  • Cache that native memory in a ConditionalWeakTable.
  • Free it when the NSObject is freed (but not before).
  • Obsolete the SuperHandle property in .NET 11, and remove it in XAMCORE_5_0.

This is less performant, but any performance issues will be alleviated by
the fact that NSObject.GetSuper () will be called much less after #25376.

The great advantage is that NSObjectData is now smaller, and fits in the
tagged memory returned by ObjectiveCMarshal.CreateReferenceTrackingHandle,
which will simplify memory management a lot for CoreCLR.

Contributes towards #25383.

This is a continuation/simplification of #25405.

Store the super handle in a ConditionalWeakTable.

* Allocate native memory for it.
* Cache that native memory in a ConditionalWeakTable.
* Free it when the NSObject is freed (but not before).
* Obsolete the SuperHandle property now, and remove it in XAMCORE_5_0.

This is less performant, but any performance issues will be alleviated by
the fact that NSObject.GetSuper () will be called much less after #25376.

The great advantage is that NSObjectData is now smaller, and fits in the
tagged memory returned by `ObjectiveCMarshal.CreateReferenceTrackingHandle`,
which will simplify memory management a lot for CoreCLR.

Contributes towards #25383.
Copilot AI review requested due to automatic review settings May 18, 2026 13:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces the native NSObjectData footprint by moving the cached objc_super storage out of the struct and into per-object tracked native memory, supporting future CoreCLR memory-management simplification.

Changes:

  • Removes classHandle/objc_super storage from NSObjectData and updates the Objective-C type encoding.
  • Adds reusable tracked native memory for NSObjectData and cached objc_super instances.
  • Obsoletes NSObject.SuperHandle for .NET 11 and hides it for XAMCORE_5_0.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/ObjCRuntime/Registrar.cs Updates the registered NSObjectData Objective-C signature.
src/Foundation/NSObject2.cs Moves super-handle storage to a ConditionalWeakTable and updates SuperHandle compatibility behavior.
runtime/xamarin/runtime.h Mirrors the reduced native NSObjectData layout and signature comment.

Comment thread src/Foundation/NSObject2.cs Resolved
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne
rolfbjarne enabled auto-merge (squash) May 18, 2026 16:17
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #1d4732f] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: 1d4732f671c1945360a7c228b10f8814f16648bc [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #1d4732f] Build passed (Build packages) ✅

Pipeline on Agent
Hash: 1d4732f671c1945360a7c228b10f8814f16648bc [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 1d4732f671c1945360a7c228b10f8814f16648bc [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #1d4732f] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: 1d4732f671c1945360a7c228b10f8814f16648bc [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🚀 [CI Build #1d4732f] Test results 🚀

Test results

✅ All tests passed on VSTS: test results.

🎉 All 183 tests passed 🎉

Tests counts

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. (⚠️ Html Report Publish failed ⚠️) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 18 tests passed. Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 20 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 18 tests passed. [attempt 5] Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ windows: All 3 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

✅ Linux build succeeded

Pipeline on Agent
Hash: 1d4732f671c1945360a7c228b10f8814f16648bc [PR build]

@rolfbjarne
rolfbjarne merged commit 4176951 into main May 22, 2026
52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants