从可靠的字典中删除项目实际上并不会从内存中删除它们 [英] Removing items from reliable dictionary doesn't actually remove them from memory
问题描述
我正在使用全状态服务,并且正在使用可靠的字典作为工作项存储.代码方面:
I'm having statefull service, and I'm using reliable dictionary as a work item store. Code-wise:
var workItemStore =
this.StateManager.GetOrAddAsync<IReliableDictionary<TKey, TValue>>(storeName);
内部调试显示这是对DistributedDictionary
类的包装的返回,该包装使用TStore
类进行繁重的操作.
Debugging internals shows this is a returns a wrapper over DistributedDictionary
class, that is using TStore
class to do heavy lifting.
我有一个工作项处理器(有点像队列),在其中将值添加到此存储区(workItemStore
),完成后将其删除.但是,当我进行内存转储时,即使显式GC.Collect()
之后,我仍然可以看到旧的(已删除的)键和值仍然存在.
I have a work item processor (kind of like queue), in which I'm adding values to this store (workItemStore
) and after I'm done I'm removing them. However when I make memory dump I still can see the old (removed) keys and values to be present even after explicitly 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
向下钻LockManager
,ReaderWriterLockSlim
和Dictionary<UInt64, LockHashValue>
指向TStore
中的值.
Drilling down LockManager
, ReaderWriterLockSlim
and Dictionary<UInt64, LockHashValue>
points to values in TStore
.
有没有办法强制从IReliableDictionary
中清除项目(即从内存中删除已删除的项目)?
Is there a way how to force cleanup of items from IReliableDictionary
(i.e. remove removed items from memory) ?
推荐答案
深入研究此问题后,问题是删除仅是逻辑删除-实际上并未从内存中删除项目.尽管将内存中的更改序列化到磁盘后,删除仍应最终发生.
After digging into this the problem is that removal is only logical removal - it doesn't actually remove items from memory. The removal should happen eventually though when in-memory changes are serialized to disk.
这篇关于从可靠的字典中删除项目实际上并不会从内存中删除它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!