Closed
Description
There appears to be a small memory leak in RestClient.ExecuteInternal
caused by the following code:
var timeoutCts = new CancellationTokenSource(request.Timeout > 0 ? request.Timeout : int.MaxValue);
var cts = CancellationTokenSource.CreateLinkedTokenSource(timeoutCts.Token, cancellationToken);
CancellationTokenSource
does not have a finalizer, so my understanding is it needs to be explicitly disposed. I have made a custom build of RestSharp that adds using statements as shown below. This change fixes the leak.
using var timeoutCts = new CancellationTokenSource(request.Timeout > 0 ? request.Timeout : int.MaxValue);
using var cts = CancellationTokenSource.CreateLinkedTokenSource(timeoutCts.Token, cancellationToken);
My application is making a high volume of requests, so this leak causes the system to run out of memory in about 2 hours.
Expected Behavior
No leaked memory
Actual Behavior
Leaked memory
Steps to Reproduce the Problem
- Execute a request using RestClient
- Profile using dotMemory by JetBrains
Specifications
- Version: 107.0.0-preview.17
- Platform: Windows 10, Ubuntu 20.04 (.NET 6)
Metadata
Metadata
Assignees
Labels
No labels