如您在附件图像中所见,总堆大小小于9MB,但进程内存使用量几乎为22GB。这是一个间歇性错误,我无法可靠地重现,因此我正在努力调试问题。我需要寻找什么来跟踪这种用法?我可以使用哪些工具来查找该内存的使用位置?
这是一个运行时间很长的过程,该问题每隔几天就会出现一次,所以我不能现实地使用会大大减慢该过程的工具,因为我可能需要等待数周才能重现该问题。
我目前使用PrivateMemorySize64
检测到该问题,并通过电子邮件提醒自己。我想知道是否有任何.NET库可以在问题发生时用来彻底分析内存使用情况以缩小问题范围?
更新-我使用Debugdiag来缩小问题的范围,现在的问题是我不确定自己在看什么。
这听起来很糟糕:
\clr.dll is responsible for 8.06 GBytes worth of outstanding allocations. The following are the top 2 memory consuming functions:
clr!EEHeapAllocInProcessHeap+46: 7.46 GBytes worth of outstanding allocations.
clr!CExecutionEngine::ClrVirtualAlloc+4f: 623.06 MBytes worth of outstanding allocations.
从分配大小看功能,毫不奇怪,分配的大多数内存是由分配的内存引起的。
clr!EEHeapAllocInProcessHeap+46 - 7.46 GBytes
然后,我查看堆栈跟踪以尝试弄清正在发生的事情,但是它们都没有引用我的任何代码,我认为这并不奇怪,因为我假设它没有显示托管代码,那我从这里去哪里?
Function details
Function clr!EEHeapAllocInProcessHeap+46
Source Line
Allocation type Heap allocation(s)
Heap handle 0x00000000`00000000
Allocation Count 1962310 allocation(s)
Allocation Size 7.46 GBytes
Leak Probability 12%
Call stack sample 1
Address 0x00000000`00000000
Allocation Time 00:05:42 since tracking started
Allocation Size 1.2 KBytes
LeakTrack+1f109
clr!EEHeapAllocInProcessHeap+46
clr!ThreadStore::AllocateOSContext+20
clr!ThreadSuspend::SuspendRuntime+1f2
clr!ThreadSuspend::SuspendEE+128
clr!WKS::GCHeap::GarbageCollectGeneration+b7
clr!WKS::gc_heap::trigger_gc_for_alloc+2d
clr!JIT_New+4d6
0x7FFC776370A1
Call stack sample 2
Address 0x00007ffc`d711d888
Allocation Time 00:05:59 since tracking started
Allocation Size 1.95 KBytes
LeakTrack+1f109
clr!EEHeapAllocInProcessHeap+46
clr!operator new+24
clr!SetupUnstartedThread+20
clr!ThreadNative::SetStart+c4
mscorlib_ni!System.Threading.Thread.SetStartHelper(System.Delegate, Int32)$##6003C20+138
0x7FFC7743DD30
Call stack sample 3
Address 0x00000000`00000000
Allocation Time 00:05:59 since tracking started
Allocation Size 1.2 KBytes
LeakTrack+1f109
clr!EEHeapAllocInProcessHeap+46
clr!operator new+24
clr!Thread::Thread+409
clr!SetupUnstartedThread+32
clr!ThreadNative::SetStart+c4
mscorlib_ni!System.Threading.Thread.SetStartHelper(System.Delegate, Int32)$##6003C20+138
0x7FFC7743DD30
Call stack sample 4
Address 0x00000040`00000000
Allocation Time 00:05:59 since tracking started
Allocation Size 16 Bytes
LeakTrack+1f109
clr!EEHeapAllocInProcessHeap+46
clr!operator new+24
clr!Thread::Thread+472
clr!SetupUnstartedThread+32
clr!ThreadNative::SetStart+c4
mscorlib_ni!System.Threading.Thread.SetStartHelper(System.Delegate, Int32)$##6003C20+138
0x7FFC7743DD30
Call stack sample 5
Address 0x00000000`00000000
Allocation Time 00:05:59 since tracking started
Allocation Size 520 Bytes
LeakTrack+1f109
clr!EEHeapAllocInProcessHeap+46
clr!operator new+24
clr!RCWStackHeader::RCWStackHeader+2b
clr!Thread::Thread+487
clr!SetupUnstartedThread+32
clr!ThreadNative::SetStart+c4
mscorlib_ni!System.Threading.Thread.SetStartHelper(System.Delegate, Int32)$##6003C20+138
0x7FFC7743DD30
Call stack sample 6
Address 0x00000000`00000000
Allocation Time 00:05:59 since tracking started
Allocation Size 24 Bytes
LeakTrack+1f109
clr!EEHeapAllocInProcessHeap+46
clr!Thread::InitThread+d9
clr!Thread::HasStarted+c1
clr!ThreadNative::KickOffThread+a7
clr!Thread::intermediateThreadProc+86
kernel32!BaseThreadInitThunk+14
ntdll!RtlUserThreadStart+21
Call stack sample 7
Address 0x00007ffc`d711d888
Allocation Time 00:05:59 since tracking started
Allocation Size 1.95 KBytes
LeakTrack+1f109
clr!EEHeapAllocInProcessHeap+46
clr!operator new+24
clr!SetupUnstartedThread+20
clr!ThreadNative::SetStart+c4
mscorlib_ni!System.Threading.Thread.SetStartHelper(System.Delegate, Int32)$##6003C20+138
0x7FFC77447620
Call stack sample 8
Address 0x00000000`00000000
Allocation Time 00:05:59 since tracking started
Allocation Size 520 Bytes
LeakTrack+1f109
clr!EEHeapAllocInProcessHeap+46
clr!operator new+24
clr!RCWStackHeader::RCWStackHeader+2b
clr!Thread::Thread+487
clr!SetupUnstartedThread+32
clr!ThreadNative::SetStart+c4
mscorlib_ni!System.Threading.Thread.SetStartHelper(System.Delegate, Int32)$##6003C20+138
0x7FFC77447620
Call stack sample 9
Address 0x00000231`fc8b24d0
Allocation Time 00:25:29 since tracking started
Allocation Size 3.99 KBytes
LeakTrack+1f109
clr!EEHeapAllocInProcessHeap+46
clr!operator new+24
clr!SyncBlockCache::GetNextFreeSyncBlock+6f
clr!ObjHeader::GetSyncBlock+6b
clr!JITutil_MonEnterWorker+da
0x7FFC7763317D
Call stack sample 10
Address 0x00000231`fc8ab460
Allocation Time 00:26:50 since tracking started
Allocation Size 3.99 KBytes
LeakTrack+1f109
clr!EEHeapAllocInProcessHeap+46
clr!operator new+24
clr!SyncBlockCache::GetNextFreeSyncBlock+6f
clr!ObjHeader::GetSyncBlock+6b
clr!JITutil_MonEnterWorker+da
0x7FFC7763317D