-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release/5.0-rc2] Memory Leak in Microsoft.Extensions.Caching.Memory …
…when handling exceptions (#42494) * Memory Leak in Microsoft.Extensions.Caching.Memory when handling exceptions When an exception is thrown inside MemoryCache.GetOrCreate, we are leaking CacheEntry objects. This is because they are not being Disposed properly, and the async local CacheEntryStack is growing indefinitely. The fix is to ensure the CacheEntry objects are disposed correctly. In order to do this, I set a flag to indicate whether the CacheEntry.Value has been set. If it hasn't, Disposing the CacheEntry won't add it to the cache. Fix #42321 * Fix another memory leak when one cache depends on another cache. The inner cache's entries will reference the outer cache entries through the ScopeLease object. Null'ing out the CacheEntry._scope field when it is disposed fixes this issue. Co-authored-by: Eric Erhardt <[email protected]>
- Loading branch information
1 parent
b0c1a41
commit 25db678
Showing
3 changed files
with
73 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters