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
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?
Maybe the file_byte_array is referenced by other objects and therefore cannot be freed.
Sign in to comment
Sort by: Most helpful
file_byte_array is not referred by other objects. I tried with GC.Collect(), memory is getting released. Why memory is not releasing immediately after memory cache expires ?