2017-02-16 75 views
1

我正在調查我們有一個wcf應用程序的內存問題,我正在使用perfview來挖掘內存。我們獲得了基礎快照,然後獲得了內存高時的快照。我對它們進行了分析,並查看了我在2921MB處看到的未獲取內存的數據。我的理解是,未獲得的記憶意味着它已經準備好了GC'd。它已經超過16小時,無法訪問的內存不斷攀升。PerfView無法訪問的內存

什麼會導致GC不收集無法訪問的內存?

enter image description here

UPDATE

我能得到終結隊列的轉儲當服務消費顯著內存。我在這份報告中究竟應該尋找什麼?或者也許應該運行其他windbg/sos/sosex命令?

0:037> !finalizequeue 
SyncBlocks to be cleaned up: 0 
Free-Threaded Interfaces to be released: 0 
MTA Interfaces to be released: 0 
STA Interfaces to be released: 0 
---------------------------------- 
------------------------------ 
Heap 0 
generation 0 has 464 finalizable objects (0000000033877190->0000000033878010) 
generation 1 has 52 finalizable objects (0000000033876ff0->0000000033877190) 
generation 2 has 19958 finalizable objects (0000000033850040->0000000033876ff0) 
Ready for finalization 228791 objects (0000000033878010->0000000033a36dc8) 
------------------------------ 
Heap 1 
generation 0 has 1508 finalizable objects (000000002ee2e168->000000002ee31088) 
generation 1 has 91 finalizable objects (000000002ee2de90->000000002ee2e168) 
generation 2 has 23498 finalizable objects (000000002ee00040->000000002ee2de90) 
Ready for finalization 249421 objects (000000002ee31088->000000002f0182f0) 
------------------------------ 
Heap 2 
generation 0 has 66 finalizable objects (00000000292660d0->00000000292662e0) 
generation 1 has 63 finalizable objects (0000000029265ed8->00000000292660d0) 
generation 2 has 19411 finalizable objects (0000000029240040->0000000029265ed8) 
Ready for finalization 238531 objects (00000000292662e0->00000000294380f8) 
------------------------------ 
Heap 3 
generation 0 has 510 finalizable objects (0000000034e470d8->0000000034e480c8) 
generation 1 has 77 finalizable objects (0000000034e46e70->0000000034e470d8) 
generation 2 has 19910 finalizable objects (0000000034e20040->0000000034e46e70) 
Ready for finalization 226933 objects (0000000034e480c8->0000000035003470) 
Statistics for all finalizable objects (including all objects ready for finalization): 
       MT Count TotalSize Class Name 
000007fe9c64aba8  1   24 System.Threading.OverlappedDataCache 
000007fe9af40ea0  1   24 System.Web.Configuration.ImpersonateTokenRef 
000007fea03a8640  1   32 System.IO.Compression.ZLibNative+SafeLibraryHandle 
000007fe9dd14820  1   32 Microsoft.Win32.SafeHandles.SafeCspHandle 
000007fe9d302a50  1   32 Microsoft.Win32.SafeHandles.SafePEFileHandle 
000007fe9cf161a8  1   32 Bid+AutoInit 
000007fe9cbead60  1   32 Microsoft.Win32.SafeHandles.SafePerfProviderHandle 
000007fe9c69a200  1   32 System.Net.SafeLocalFree 
000007fe9c649080  1   32 System.ServiceModel.Channels.PipeHandle 
000007fe9c62ad18  1   32 System.Net.SafeInternetHandle 
000007fe9af42a08  1   32 Microsoft.Win32.SafeHandles.SafeFileMappingHandle 
000007fe9af42920  1   32 Microsoft.Win32.SafeHandles.SafeViewOfFileHandle 
000007fe9ad790b0  1   32 System.Web.PerfInstanceDataHandle 
000007fe9c4b08d8  1   40 System.Security.SafeBSTRHandle 
000007fe9ce69118  1   48 System.Runtime.CompilerServices.ConditionalWeakTable`2[[System.Transactions.ContextKey, System.Transactions],[System.Transactions.ContextData, System.Transactions]] 
000007fe9c62cf68  1   48 System.Runtime.IOThreadScheduler 
000007fe9af0d5f8  1   48 Microsoft.CSharp.CSharpCodeProvider 
000007fe9ae4c628  1   48 System.Runtime.CompilerServices.ConditionalWeakTable`2[[System.Object, mscorlib],[System.Runtime.Serialization.SerializationInfo, mscorlib]] 
000007fe9af43750  1   56 System.Web.Compilation.CompilationMutex 
000007fe9ae45a60  2   64 System.Security.Cryptography.SafeProvHandle 
000007fe9a91bad0  2   64 System.Threading.TimerQueue+AppDomainTimerSafeHandle 
000007fea03adee0  2   96 System.Web.Security.FileSecurityDescriptorWrapper 
000007fe9d669608  3   120 System.Threading.RegisteredWaitHandleSafe 
000007fe9c623850  3   120 System.Net.SafeRegistryHandle 
000007fe9c696808  4   128 System.Gen2GcCallback 
000007fe9a97d6b0  4   128 Microsoft.Win32.SafeHandles.SafeFileHandle 
000007fe9d8710a0  1   160 System.Threading.CdsSyncEtwBCLProvider 
000007fe9c64b368  1   160 System.Collections.Concurrent.CDSCollectionETWBCLProvider 
000007fe9c648d08  1   160 System.PinnableBufferCacheEventSource 
000007fe9be65a08  5   160 Microsoft.Win32.SafeHandles.SafeProcessHandle 
000007fe9f557760  1   168 System.Web.AspNetEventSource 
000007fe9acab410  2   176 System.Runtime.Diagnostics.EtwProvider 
000007fe9ad7daa0  8   192 System.SizedReference 
000007fe9aac5d38  2   208 System.Runtime.Remoting.Contexts.Context 
000007fe9e5a7c58  1   216 log4net.Appender.RollingFileAppender 
000007fe9c64a138  2   224 System.ServiceModel.Channels.OverlappedContext 
000007fe9cbe45c8  3   264 System.Diagnostics.PerformanceData.CounterSet 
000007fe9cda2278  9   288 System.Net.SafeCloseHandle 
000007fe9c628078  6   288 System.Net.SafeCloseSocketAndEvent 
000007fe9ad05090  2   320 System.Diagnostics.Tracing.FrameworkEventSource 
000007fe9c4be5a0  2   352 System.Data.DataSet 
000007fe9c69ee18  3   360 System.Net.TlsStream 
000007fe9a97cf10  4   416 System.IO.FileStream 
000007fe9a8afc60  14   448 Microsoft.Win32.SafeHandles.SafeRegistryHandle 
000007fe9ad05940  6   528 System.Diagnostics.Tracing.EventSource+OverideEventProvider 
000007fe9c714d60  18   576 System.Net.SafeFreeContextBuffer_SECURITY 
000007fe9c628d68  19   608 System.Net.SafeNativeOverlapped 
000007fe9cbe49d8  14   672 System.Diagnostics.PerformanceData.CounterSetInstanceCounterDataSet 
000007fe9ae78550  10   720 System.Web.DirMonCompletion 
000007fe9cbe4880  14   784 System.Diagnostics.PerformanceData.CounterSetInstance 
000007fe9f2d6db8  12   864 NewRelic.Agent.Core.Wrapper.AsyncAgentWrapperApi.Builders.TransactionBuilder 
000007fe9bcb8250  27   864 System.Net.SafeCloseSocket+InnerSafeCloseSocket 
000007fe9c6947e0  3   888 System.Net.Connection 
000007fe9bcb9d18  28   1120 System.Net.SafeCloseSocket 
000007fe9ad7bef8  35   1120 Microsoft.Win32.SafeHandles.SafeWaitHandle 
000007fe9c2de460  3   1536 System.Data.DataTable 
000007fe9c7dee68  62   2480 System.Net.SafeFreeContextBufferChannelBinding_SECURITY 
000007fe9cf19418  12   2592 System.Data.DataColumn 
000007fe9bcb6b38  28   3808 System.Net.Sockets.Socket 
000007fe9c7196c0  120   3840 System.Security.Cryptography.SafeCertChainHandle 
000007fe9c695b60  62   3968 System.Net.Sockets.NetworkStream 
000007fe9c711618  62   4960 System.Net.Security._SslStream 
000007fe9c718cf8  179   7160 System.Net.SafeCredentialReference 
000007fe9c74c9d8  240   7680 System.Security.Cryptography.SafeCertStoreHandle 
000007fe9d406ff8  377   9048 System.Reflection.Emit.DynamicResolver+DestroyScout 
000007fe9dc33bd0  342  10944 System.Security.Cryptography.SafeKeyHandle 
000007fe9cda9d00  25  11400 System.Net.Sockets.SocketAsyncEventArgs 
000007fe9f4c7440  532  17024 Devart.Common.o 
000007fe9f4e2e90  350  22400 Devart.Data.Oracle.OracleCursor 
000007fe9c5e4eb8  651  26040 System.Threading.ThreadPoolWorkQueueThreadLocals 
000007fe9f448870  792  31680 Microsoft.Practices.EnterpriseLibrary.Caching.Cache 
000007fe9f4c5d40  151  41072 Devart.Data.Oracle.a3 
000007fe9f4e0fd8  191  41256 Devart.Data.Oracle.OracleDataReader 
000007fe9f3ce7d0  191  44312 Devart.Data.Oracle.OracleCommand 
000007fe9c661238  1445  46240 System.Security.Cryptography.SafeHashHandle 
000007fe9aaa67e0  1985  47640 System.WeakReference 
000007fe9ce69d70  2193  70176 System.Transactions.SafeIUnknown 
000007fe9c71c040  2593  82976 System.Security.Cryptography.X509Certificates.SafeCertContextHandle 
000007fe9a756f58  1932  123648 System.Threading.ReaderWriterLock 
000007fe9c74f038  4788  153216 System.Security.Cryptography.SafeLocalAllocHandle 
000007fe9c749bf0  5244  167808 System.Security.Cryptography.SafeCertContextHandle 
000007fe9a706568  1942  186432 System.Threading.Thread 
000007fe9fcf5df0  1692  243648 Devart.Data.Oracle.dz 
000007fe9c71c118  6667  320016 System.Net.SafeFreeCredential_SECURITY 
000007fe9a9190e0 15031  360744 System.Threading.TimerHolder 
000007fe9be64d58  2328  651840 System.Diagnostics.Process 
000007fe9f440548 14217  1023624 Microsoft.Practices.EnterpriseLibrary.Common.Configuration.Storage.ConfigurationChangeFileWatcher 
000007fe9ce6a6e8 14217  1364832 System.Timers.Timer 
000007fe9c71c918 29980  1678880 System.Net.SafeDeleteContext_SECURITY 
000007fe9a94dd68 89958  3598320 Microsoft.Win32.SafeHandles.SafeLocalAllocHandle 
000007fe9a91b268 185991  5951712 Microsoft.Win32.SafeHandles.SafeTokenHandle 
000007fe9ad0b578 206499  14867928 System.Reflection.Emit.DynamicResolver 
000007fe9f3ca188 435920  87184000 Devart.Data.Oracle.OracleConnection 
Total 1029284 objects 

「準備完成」對象的數量對我來說很重要。不應該是零,或至少少於幾百?

+0

看起來像終結器線程死鎖。啓用非託管調試並查看其堆棧跟蹤以查看它掛起的位置。 –

+0

我們不能在開發環境中重現這一點。這只是發生在產品中。有沒有辦法獲得終結器線程的堆棧跟蹤?我會看看windgb,看看它能否提供更多細節。 –

回答

1

如果您將錯誤應用IDisposable,GC將不會收集內存。根據截圖,你提供的,你
1.沒有關閉連接到Oracle數據庫(我談到Devart.Data.Oracle ....片段)。不要依賴oracle db連接的密切方法,而應考慮使用using運算符,它將爲您提供確定性的垃圾回收。
2.提到DynamicResolver的第二行指向了某種依賴注入。從我的經驗來看,我認爲你的依賴注入庫不知道如何清理你的對象。這實際上可以通過爲您的類實現IDisposable接口來解決,這是DI庫使用的接口。
3.第三線,其中有以下子:Win32.SafeHandles.SafeTokenHandle給出了大概你使用一些系統資源,或一些.NET領域也經常稱爲非託管資源之外的暗示。對於他們,您需要實施內存清理和IDisposable以及Finalizer連接。有關更多詳細信息,請參閱此link

0

它已經超過16個小時,無法訪問的內存不斷攀升。 什麼會導致GC不收集無法訪問的內存?

當任何一代中的對象的大小運行特定閾值時,GC將運行。下面是一些近似的值:

  • 代0的命中〜256千
  • 創1次命中〜2 MB(第0級和第1代收集)
  • Gen 2次的命中〜10 MB(第0級, 1代和2代收集)
  • 操作系統發送一個低內存通知
  • GC.Collect的()被調用(這不只是特殊情況下是個好主意)

你的應用A n內存在2,921MB,所以下一次收集不會發生一段時間。自從GC不以每秒x秒/分鐘/小時的速度運行,而是基於上述條件運行16或1600小時無關緊要。

要問自己的一個更好的問題是要明白爲什麼這些對象不會被收集到Gen 0集合中。找出Gen 0中沒有收集哪些物體,然後問問自己:這些物體是否真的需要這麼長時間?

  1. 請確保您在不需要的時候儘快處置對象。
  2. 請勿將物體放置在比他們需要的時間更長的地方。
+0

2.9 GB的內存全部都在第2代。我知道GC在第2代上並不經常運行,但它似乎有幾乎3 GB的內存用於第2代,它會運行並清理它。我認爲你的另一點非常好,就是爲什麼這些對象不是在第1代收集的。 –

+0

他們沒有被收集,因爲它們在那時被引用,所以他們進入Gen 1和Gen 2。 – CodingYoshi