CommunityToolkit / CommunityToolkit/dotnet

AsyncCollectionRequestMessage<T> creates a CancellationTokenSource that never gets disposed

Open
#1,117 1 comment 0 reactions 0 assignees View on GitHub
bug :bug:
Dominant language
C#
Stars
3.8k
Forks
400
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

I was examining the code for the the [AsyncCollectionRequestMessage](https://github.com/CommunityToolkit/dotnet/blob/main/src/CommunityToolkit.Mvvm/Messaging/Messages/AsyncCollectionRequestMessage%7BT%7D.cs) class and I noticed it creates a private `CancellationTokenSource` that never gets Dispose() called on it.

I looked at `CancellationTokenSource`'s dispose methods and it's non-trivial, potentially disposing of a `System.ITimer` and a `ManualResetEvent` - both things that are potentially finite resources, so better to release ASAP.

### Regression

_No response_

### Steps to reproduce

No reproduction, just observation of the code.

### Expected behavior

There should be an opportunity to dispose the CancellationTokenSource. Most obvious possible way would be to make thing that comes to mind would be make `AsyncCollectionRequestMessage` implement `IDispose` so that users could call it.

### Screenshots

_No response_

### IDE and version

VS 2022

### IDE version

17.14.11

### Nuget packages

- [ ] CommunityToolkit.Common
- [ ] CommunityToolkit.Diagnostics
- [ ] CommunityToolkit.HighPerformance
- [x] CommunityToolkit.Mvvm (aka MVVM Toolkit)

### Nuget package version(s)

8.4.0

### Additional context

_No response_

### Help us help you

Yes, I'd like to be assigned to work on this item

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.