Skip to content

fix(bindings): harden C# bindings and tests, add pooling, bump 0.9#571

Open
anakrish wants to merge 1 commit intomicrosoft:mainfrom
anakrish:csharp-memory-growth
Open

fix(bindings): harden C# bindings and tests, add pooling, bump 0.9#571
anakrish wants to merge 1 commit intomicrosoft:mainfrom
anakrish:csharp-memory-growth

Conversation

@anakrish
Copy link
Collaborator

@anakrish anakrish commented Feb 6, 2026

  • Add SafeHandleWrapper gating with 30s dispose timeout to prevent native leaks; keep handle types internal.
  • Remove IsClosed checks inside SafeHandle.ReleaseHandle (SafeHandle sets IsClosed before invoking ReleaseHandle), so native drops are not skipped.
  • Add memory growth tests (using/finalizer paths) with GC cadence, limits, and clearer output.
  • Extend xtask C# runner (filtering, console logger, skip apps) and defaults.
  • Centralize result handling, pooled marshalling utilities, IReadOnlyList overloads, readonly PolicyModule; tighten MemoryLimits checks.
  • Tweak registry helpers/enums; format C# code; bump versions and changelog.

fixes #570
closes #554

@anakrish anakrish mentioned this pull request Feb 6, 2026
@anakrish anakrish force-pushed the csharp-memory-growth branch 2 times, most recently from 74248ef to 7e16cb9 Compare February 6, 2026 12:10
@anakrish anakrish changed the title fix(bindings): address C# handle release and add memory growth checks fix(bindings): harden C# bindings and tests, add pooling, bump 0.9 Feb 6, 2026
@anakrish anakrish force-pushed the csharp-memory-growth branch from 7e16cb9 to 5cc3162 Compare February 6, 2026 12:49
@billknye
Copy link

billknye commented Feb 6, 2026

Confirmed at least in my basic tests, the changes here resolve the continual memory growth.

Thanks for resolving this!

@anakrish anakrish force-pushed the csharp-memory-growth branch 2 times, most recently from ba3ad89 to 3fe0da6 Compare February 6, 2026 14:32
@anakrish
Copy link
Collaborator Author

anakrish commented Feb 6, 2026

@billknye Thanks for trying it out and confirming the fix. I have pushed a version with more clean up and refactor. Mainly address scenario where a thread could dispose a C# wrapper (and hence potentially free the rust object) while another thread is using it.

@anakrish anakrish force-pushed the csharp-memory-growth branch 2 times, most recently from b1f65da to a9a5e3d Compare February 6, 2026 14:52
- Introduce SafeHandleWrapper with gating, short drain wait, and deferred release on last in-flight exit.
- Wire Engine/Program/Rvm/CompiledPolicy to wrapper (centralized handle use, interop helper).
- Add C# memory growth tests (using/finalizer paths) and extend xtask C# runner options.
- Add pooled marshalling utilities, ResultHelpers, and API cleanups; update versions/changelog.

Fixes microsoft#570. Closes microsoft#554

Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
@anakrish anakrish force-pushed the csharp-memory-growth branch from a9a5e3d to 9d2b1ba Compare February 7, 2026 03:30
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.

[bindings][c#] Memory leak Revisit C# binding

2 participants