【发布时间】:2017-09-24 03:45:10
【问题描述】:
我正在尝试找出为什么我们的一个站点使用 2.3GB 内存。从 windbg,当我运行 !dumpheap -stat 时,我得到了这个:
000007fe992ae8d8 39413 11489246 System.Byte[]
000007fe992abf40 8567 14995548 System.Char[]
000007fe994500b0 31763 31617136 System.Int32[]
000007fe9c7b4cf8 1221470 48858800 XXXXXXX.SearchService+SectorItem
000007fe9925ba30 219828 49646032 System.Object[]
000007fe992a46f0 4273039 264621916 System.String
0000000002a35c10 2214 923713198 Free
Total 6994094 objects
Fragmented blocks larger than 0.5 MB:
Addr Size Followed by
000000010625ef50 1.2MB 00000001063982e0 System.Collections.Hashtable
00000001064c9ed0 4.4MB 0000000106932128 System.Object[]
0000000206a4ee48 0.6MB 0000000206ae0a10 System.String
0000000206d270a0 3.9MB 0000000207106058 Free
0000000305282098 0.8MB 000000030534d248 System.Xml.XmlElementListListener
00000003053c5ad0 0.9MB 00000003054a87c0 System.String
0000000406a8b0f0 1.9MB 0000000406c73f10 System.WeakReference
0000000406c7aac8 2.2MB 0000000406ea43a8 System.Byte[]
0000000406ef89a8 1.5MB 00000004070721d8 System.Collections.Concurrent.ConcurrentDictionary`2+Node[[System.String, mscorlib],[System.DateTime, mscorlib]]
0000000407072208 1.2MB 00000004071a77c0 System.Threading.ThreadPoolWorkQueueThreadLocals
00000004073d1110 11.3MB 0000000407f1a7f8 Free
我们可以看到有超过 900MB 的“空闲”对象并且从未从 IIS 内存中释放(我看了几天的图表)。如果我这样做,则有 2200 个免费对象:
!dumpheap -mt 0000000002a35c10
有很多免费对象:
00000005310b8008 0000000002a35c10 30 Free
00000005310dce28 0000000002a35c10 30 Free
0000000531101a50 0000000002a35c10 30 Free
0000000531126870 0000000002a35c10 30 Free
000000053114c680 0000000002a35c10 30 Free
0000000531187ee8 0000000002a35c10 30 Free
00000005311c3538 0000000002a35c10 30 Free
00000005311fefe0 0000000002a35c10 18583286 Free
0000000532a5e3a0 0000000002a35c10 9499822 Free
0000000533383848 0000000002a35c10 9830638 Free
0000000533d98db8 0000000002a35c10 46462326 Free
0000000536a40d70 0000000002a35c10 30 Free
0000000536a6f300 0000000002a35c10 10549646 Free
00000005374cf138 0000000002a35c10 10246582 Free
0000000537ee4f98 0000000002a35c10 80664406 Free
000000053cccb570 0000000002a35c10 22118654 Free
根据这篇文章: https://www.simple-talk.com/dotnet/.net-framework/the-dangers-of-the-large-object-heap/ 任何大于 85000 字节的内容都不会被自动回收。 那么我可以得出结论,我们在内存中有一些非常大的对象(例如,可能是一个大字典)并且永远不会被 GC 删除吗?所以这是一个LOH问题而不是内存泄漏问题?
如果是 LOH 问题,如果大对象在缓存中(如此重用)或在内存中使用一次,是否有什么区别? GC 会收集其中任何一个吗?
【问题讨论】: