[UIKit] Fix GCHandle memory leak in NetworkReachability.SetNotification. Fixes #12962.#24147
Conversation
- Free GCHandle when callback is removed via SetNotification(null) - Free GCHandle if SCNetworkReachabilitySetCallback fails - Override Dispose to ensure GCHandle is always freed Fixes #12962
Test verifies that SetNotification can be called multiple times and that clearing the notification works properly. Related to #12962
Add SetNotification_GCHandleFreed test that: - Creates 10 NetworkReachability instances on a background thread - Sets notifications to allocate GCHandles - Disposes the instances to free the GCHandles - Waits for background thread on main thread - Forces garbage collection - Asserts that at least one instance was collected by GC This test verifies that the GCHandle leak fix works correctly and objects can be garbage collected after disposal.
Add SetNotification_GCHandleFreedWithNull test that: - Creates 10 NetworkReachability instances on a background thread - Sets notifications to allocate GCHandles - Calls SetNotification(null) to clear and free the GCHandles - Waits for background thread on main thread - Forces garbage collection - Asserts that at least one instance was collected by GC This test specifically validates that calling SetNotification(null) properly frees the GCHandle, allowing objects to be garbage collected.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [CI Build #85b600d] Build passed (Build packages) ✅Pipeline on Agent |
✅ [PR Build #85b600d] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
✅ [CI Build #85b600d] Build passed (Build macOS tests) ✅Pipeline on Agent |
💻 [CI Build #85b600d] Tests on macOS X64 - Mac Sonoma (14) passed 💻✅ All tests on macOS X64 - Mac Sonoma (14) passed. Pipeline on Agent |
💻 [CI Build #85b600d] Tests on macOS M1 - Mac Monterey (12) passed 💻✅ All tests on macOS M1 - Mac Monterey (12) passed. Pipeline on Agent |
💻 [CI Build #85b600d] Tests on macOS M1 - Mac Ventura (13) passed 💻✅ All tests on macOS M1 - Mac Ventura (13) passed. Pipeline on Agent |
💻 [CI Build #85b600d] Tests on macOS arm64 - Mac Sequoia (15) passed 💻✅ All tests on macOS arm64 - Mac Sequoia (15) passed. Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
💻 [CI Build #85b600d] Tests on macOS arm64 - Mac Tahoe (26) passed 💻✅ All tests on macOS arm64 - Mac Tahoe (26) passed. Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #85b600d] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 120 tests passed 🎉 Tests counts✅ cecil: All 1 tests passed. Html Report (VSDrops) Download Pipeline on Agent |
Mostly implemented using command-line Copilot.
Fixes #12962.