Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我应该在不再使用时显式清除非全局ConcurrentDictionary,还是GC检测到它不再使用?_C#_.net_Memory Management_Memory Leaks_F# - Fatal编程技术网

C# 我应该在不再使用时显式清除非全局ConcurrentDictionary,还是GC检测到它不再使用?

C# 我应该在不再使用时显式清除非全局ConcurrentDictionary,还是GC检测到它不再使用?,c#,.net,memory-management,memory-leaks,f#,C#,.net,Memory Management,Memory Leaks,F#,我应该在不再使用时显式清除非全局ConcurrentDictionary,还是GC检测到它不再使用 这有点相关: 编辑: 我问的原因是,我有以下代码(此处简化): let myMethod()= 异步的{ 让myEventList=ConcurrentDictionary() 使用o=myEvent |>Observable.subscribe(有趣的e-> myEventList.GetOrAdd(e,true)|>忽略) let!res=doAsyncThingsCausingEvents

我应该在不再使用时显式清除非全局ConcurrentDictionary,还是GC检测到它不再使用

这有点相关:


编辑: 我问的原因是,我有以下代码(此处简化):

let myMethod()=
异步的{
让myEventList=ConcurrentDictionary()
使用o=myEvent |>Observable.subscribe(有趣的e->
myEventList.GetOrAdd(e,true)|>忽略)
let!res=doAsyncThingsCausingEvents()
myEventList |>Seq.iter(fun(e,|)->Console.WriteLine“We had”+e.ToString())
物件
}

…事实上,当在多个线程中多次并行调用时,它会泄漏内存。

一个有趣的问题。
ConcurrentDictionary
不可
IDisposable
,因此我希望它能像任何其他对象一样工作。i、 e.当不再引用时,应符合收集条件,包括没有其他引用的所有物品

通过分配ConcurrentDictionary、清空引用和捕获内存快照进行快速测试表明,情况确实如此