问题描述
症状:在WindowsServer2008标准版、2008R2标准版、WindowsServer2012标准版中,程序运行一段时间以后,使用内存暴涨,如不重启,内存会被程序占用完。但是在WindowsServer2003标准版中内存使用是正常的(30M左右)使用Adplushang模式,抓出了dump文件,大小约4.3GB.在WinDbg中,!EEHeap-stat的结果如下:--------------------------------------TotalLoaderHeapsize:0x4b608000(1264615424)bytes=======================================NumberofGCHeaps:1generation0startsat0x0000000010ed0ce0generation1startsat0x0000000010e8ec78generation2startsat0x0000000002671000ephemeralsegmentallocationcontext:nonesegmentbeginallocatedsize000000000267000000000000026710000000000010fbdf080x000000000e94cf08(244633352)Largeobjectheapstartsat0x0000000012671000segmentbeginallocatedsize0000000012670000000000001267100000000000199ba1c00x00000000073491c0(120885696)TotalSize0x15c960c8(365519048)------------------------------GCHeapSize0x15c960c8(365519048)可以看到Heap才365M,但是DumpFile却有4.3GB.另外就是LoaderHeap有1.2GB.加上-loader参数以后,发现有几千个module,如下Module000007ff4ff70b28:Size:0x0(0)bytes.Module000007ff4ff724e8:Size:0x0(0)bytes.Module000007ff4ff73ea8:Size:0x0(0)bytes.Module000007ff4ff75868:Size:0x0(0)bytes.Module000007ff4ff77228:Size:0x0(0)bytes.Module000007ff4ff78be8:Size:0x0(0)bytes.Module000007ff4ff7a5a8:Size:0x0(0)bytes.Module000007ff4ff7bf68:Size:0x0(0)bytes.Module000007ff4ff7d928:Size:0x0(0)bytes.Module000007ff4ff7f2e8:Size:0x0(0)bytes.Module000007ff4ffb0d30:Size:0x0(0)bytes.Module000007ff4ffb26f0:Size:0x0(0)bytes.Module000007ff4ffb40b0:Size:0x0(0)bytes.Module000007ff4ffb5a70:Size:0x0(0)bytes.Module000007ff4ffb7430:Size:0x0(0)bytes.Module000007ff4ffb8df0:Size:0x0(0)bytes.Module000007ff4ffba7b0:Size:0x0(0)bytes.Module000007ff4ffbc170:Size:0x0(0)bytes.Module000007ff4ffbdb30:Size:0x0(0)bytes.Module000007ff4ffbf4f0:Size:0x0(0)bytes.Module000007ff4fff0f38:Size:0x0(0)bytes.Module000007ff4fff28f8:Size:0x0(0)bytes.Module000007ff4fff42b8:Size:0x0(0)bytes.........随机检查过很多个module,发现内容其实是一样的,如下0:019>!Dumpmodule-mt000007ff504f80e0Name:3jrktwys,Version=0.0.0.0,Culture=neutral,PublicKeyToken=nullAttributes:PEFileAssembly:000000015915cba0LoaderHeap:0000000000000000TypeDefToMethodTableMap:000007ff5050aa78TypeRefToMethodTableMap:000007ff5050aae8MethodDefToDescMap:000007ff5050ac68FieldDefToDescMap:000007ff5050af08MemberRefToDescMap:000007ff5050b378FileReferencesMap:000007ff5050b550AssemblyReferencesMap:000007ff5050b558MetaDatastartaddress:000000015a262264(9088bytes)TypesdefinedinthismoduleMTTypeDefName------------------------------------------------------------------------------000007ff504f88080x02000002WMINET_Converter000007ff504f89180x02000003IWmiConverter000007ff504f8ae00x02000004ConvertClass_0000007ff504f8ce80x02000005ConvertClass_1000007ff504f8ef00x02000006ConvertClass_2000007ff504f91380x02000007ConvertClass_3000007ff504f93400x02000008ConvertClass_4000007ff504f95c80x02000009ConvertClass_5000007ff504f97f00x0200000aConvertClass_6000007ff504f99f80x0200000bConvertClass_7TypesreferencedinthismoduleMTTypeRefName------------------------------------------------------------------------------000007fef8c975900x01000001System.Object000007fef8c9f5f80x01000002System.Collections.Hashtable000007fef8c925a80x01000005System.Guid000007ff002454400x0100000cMicrosoft.Practices.EnterpriseLibrary.Data.Instrumentation.DataServiceEvent000007fef8c999780x0100000dSystem.Type000007ff00248e480x0100000fMicrosoft.Practices.EnterpriseLibrary.Data.Instrumentation.DataConnectionFailedEvent000007ff002495800x01000010Microsoft.Practices.EnterpriseLibrary.Data.Instrumentation.DataTransactionFailedEvent000007ff002497480x01000011Microsoft.Practices.EnterpriseLibrary.Data.Instrumentation.DataServiceFailureEvent000007ff002455900x01000012Microsoft.Practices.EnterpriseLibrary.Data.Instrumentation.DataConnectionOpenedEvent000007ff00249d180x01000013Microsoft.Practices.EnterpriseLibrary.Data.Instrumentation.DataServiceConfigFailureEvent000007ff00249e900x01000014Microsoft.Practices.EnterpriseLibrary.Data.Instrumentation.DataCommandFailedEvent000007ff0024a4680x01000015Microsoft.Practices.EnterpriseLibrary.Data.Instrumentation.DataTransactionRolledBackEvent我的代码中并没有类似WMINET_ConverterIWmiConverter之类的定义,但是有引用微软的企业库.从微软公布的.netsourcecode中查到,这几个class貌似属于System.Management.Instrumentation名称空间下的定义。不知道是哪里出了问题,导致出现占用大量的内存?(补充:如果将Windows2008打到最新的补丁,这个内存泄露的问题也可以解决。但因为补丁太多,具体不知道是哪个解决的这个问题,有高人能提点下么?)
解决方案
解决方案二:
自己顶!!!
解决方案三:
去微软中文技术社区问微软的专业客服
解决方案四:
这类问题还真没碰到过
解决方案五:
貌似很深奥的样子啊,帮顶
解决方案六:
.netmemoryprofiler内存泄漏的测试工具,希望可以帮到你
解决方案七:
看看KB977357:http://support.microsoft.com/kb/977357
解决方案八:
额,新手,后面的字节什么的没看懂
解决方案九:
既然将Windows2008打到最新的补丁,这个内存泄露的问题也可以解决那么显然是操作系统本身的bug造成的,你试图用自己的代码去解决问题,显然是不合适的最好把那个也字去掉
解决方案十:
看着晕。向大神们致敬