Therefore, the memory is released, but not reported to you immediately, because the system does not execute GC.Collect if it is not needed yet. (Calling GC.Collect too frequently and at the inappropriate time usually reduces the overall performance).
Memory cache is not getting released after expiration
Pavithra V
21
Reputation points
I used System.Runtime.Caching.ObjectCache to store images in video. After expiration interval, cache is getting expired. But memory didn’t get released. Same behavior was observed in .Net framework 4.6.1 and .Net 5.0. Please find the code snippet below
int expiration_interval_minutes = 5;
ObjectCache cache = MemoryCache.Default;
CacheItemPolicy policy = new CacheItemPolicy();
policy.SlidingExpiration = TimeSpan.FromMinutes(expiration_interval_minutes);
string cacheKey = "some_key";
cache.Set(cacheKey, file_byte_array, policy);
Can anyone guide us to resolve this issue?