从可靠的字典中删除项目实际上并没有从内存中删除它们

Removing items from reliable dictionary doesn't actually remove them from memory

我有全状态服务,我使用可靠的字典作为工作项存储。代码方面:

var workItemStore = 
  this.StateManager.GetOrAddAsync<IReliableDictionary<TKey, TValue>>(storeName);

调试内部显示这是 returns DistributedDictionary class 的包装器,即使用 TStore class 来完成繁重的工作。

我有一个工作项处理器(有点像队列),我在其中向该存储添加值 (workItemStore),完成后我将删除它们。但是,当我进行内存转储时,即使在显式 GC.Collect().

之后,我仍然可以看到旧的(已删除的)键和值存在

示例内存转储:

Object type                       |     Count | Size (Bytes) | Inclusive Size (Bytes)
-------------------------------------------------------------------------------------
LockManager                       |    10,635 |   53,526,856 | 511,008,280
ReaderWriterLockSlim              | 2,772,648 |  261,374,208 | 248,745,216
TStore<Guid, WorkItem, ...>       |     3,236 |   15,999,256 | 216,851,864
Dictionary<UInt64, LockHashValue> | 2,772,560 |  217,807,600 | 207,288,816

向下钻取 LockManagerReaderWriterLockSlimDictionary<UInt64, LockHashValue> 指向 TStore 中的值。

有没有办法强制清理 IReliableDictionary 中的项目(即从内存中删除已删除的项目)?

在深入研究这个问题后,问题是删除只是逻辑删除——它实际上并没有从内存中删除项目。尽管当内存中的更改被序列化到磁盘时,最终应该会删除。