DefaultCredentialsLoader currently uses a ConcurrentDictionary which will permanently store a string and a SemaphoreSlim for every credential loaded, as it does not clean up after itself.
I am the author of AsyncKeyedLock, a popular library for key locking that has a number of dependents, including two existing Microsoft projects (Vipr and kiota).
I believe that this dependency would help reduce memory allocations through SemaphoreSlim pooling as well as clean up the dictionary after use.
// Get or create a semaphore for this credentialDescription and wait on it
using (await _loadingSemaphores.LockAsync(credentialDescription.Id))
{
if (credentialDescription.CachedValue == null)
{
if (CredentialSourceLoaders.TryGetValue(credentialDescription.SourceType, out ICredentialSourceLoader? loader))
await loader.LoadIfNeededAsync(credentialDescription, parameters);
}
};
DefaultCredentialsLoader currently uses a ConcurrentDictionary which will permanently store a string and a SemaphoreSlim for every credential loaded, as it does not clean up after itself.
I am the author of AsyncKeyedLock, a popular library for key locking that has a number of dependents, including two existing Microsoft projects (Vipr and kiota).
I believe that this dependency would help reduce memory allocations through SemaphoreSlim pooling as well as clean up the dictionary after use.