フリーオブジェクトが解放されないように見えるメモリリークに苦しんでいます。
最近、w3wp.exe のメモリが 1100 MB に達した後、私の webapp がクラッシュし始めました。接続プールがいっぱいだったため、イベント ログに db 接続タイムアウト エラーが見つかりました (300 接続に設定しました)。
windbg で dumpheap -stat を実行すると、「Free」タイプの未リリースのオブジェクトがたくさんあることがわかります。
00000071f70ac438 10300 478192918 フリー
したがって、10300 個の空きオブジェクトが約 500MB のスペースを占めます。
いくつかの大きな空きオブジェクト (およびサイズ) で !gcroot を実行すると、次のようになります。
!gcroot 00000071f7d63b78+0x509778
Thread 1bf4:
000000765f43caf0 000007faab4a7f13 System.Data.SqlClient.SqlCommand..ctor(System.Data.SqlClient.SqlCommand)
rsi:
-> 00000071f6cfd0f8 System.Data.SqlClient.SqlCommand
-> 00000071f6cff710 System.Data.SqlClient.SqlParameterCollection
-> 00000071f6cff738 System.Collections.Generic.List`1[[System.Data.SqlClient.SqlParameter, System.Data]]
-> 00000071f6cff760 System.Object[]
-> 00000071f6cff7a0 System.Data.SqlClient.SqlParameter
-> 00000071f826d2f0 System.String
000000765f43cc60 000007faa65f5832 System.Data.EntityClient.EntityCommandDefinition..ctor(System.Data.Common.DbProviderFactory, System.Data.Common.CommandTrees.DbCommandTree)
rbp+8: 000000765f43cc98 (pinned)
-> 00000071f83aef08 System.Collections.Generic.List`1[[System.Data.Query.PlanCompiler.ProviderCommandInfo, System.Data.Entity]]
-> 00000071f83aef30 System.Object[]
-> 00000071f83aeee0 System.Data.Query.PlanCompiler.ProviderCommandInfo
-> 00000071f6cfc698 System.Data.Common.CommandTrees.DbQueryCommandTree
-> 00000071f6cfc5b0 System.Data.Common.CommandTrees.DbProjectExpression
-> 00000071f6cf5f98 System.Data.Common.CommandTrees.DbExpressionBinding
-> 00000071f6cf5f40 System.Data.Common.CommandTrees.DbSortExpression
-> 00000071f6cf5de8 System.Data.Common.CommandTrees.DbExpressionBinding
-> 00000071f6cf5cd8 System.Data.Common.CommandTrees.DbProjectExpression
-> 00000071f6ced718 System.Data.Common.CommandTrees.DbExpressionBinding
-> 00000071f6ced600 System.Data.Common.CommandTrees.DbJoinExpression
-> 00000071f6ceb3f0 System.Data.Common.CommandTrees.DbExpressionBinding
-> 00000071f6ceb398 System.Data.Common.CommandTrees.DbLimitExpression
-> 00000071f6ceb340 System.Data.Common.CommandTrees.DbFilterExpression
-> 00000071f6ceb310 System.Data.Common.CommandTrees.DbAndExpression
-> 00000071f6ceb2e0 System.Data.Common.CommandTrees.DbComparisonExpression
-> 00000071f6ceb2b8 System.Data.Common.CommandTrees.DbParameterReferenceExpression
-> 00000071f826d2f0 System.String
000000765f43cc60 000007faa65f5832 System.Data.EntityClient.EntityCommandDefinition..ctor(System.Data.Common.DbProviderFactory, System.Data.Common.CommandTrees.DbCommandTree)
rbp+190: 000000765f43ce20
-> 00000071f6ce9fb0 System.Data.Common.CommandTrees.DbQueryCommandTree
-> 00000071f6ce9f80 System.Data.Common.CommandTrees.DbLimitExpression
-> 00000071f6ce9e98 System.Data.Common.CommandTrees.DbProjectExpression
-> 00000071f6ce8100 System.Data.Common.CommandTrees.DbExpressionBinding
-> 00000071f6ce78f0 System.Data.Common.CommandTrees.DbFilterExpression
-> 00000071f8273be8 System.Data.Common.CommandTrees.DbAndExpression
-> 00000071f8273bb8 System.Data.Common.CommandTrees.DbComparisonExpression
-> 00000071f826d320 System.Data.Common.CommandTrees.DbParameterReferenceExpression
-> 00000071f826d2f0 System.String
000000765f43cf70 000007faa655da7d System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(System.Nullable`1<System.Data.Objects.MergeOption>)
r12:
-> 00000071f6ce2768 System.Data.Objects.ELinq.ELinqQueryState
-> 00000071f6ce7aa0 System.Data.Objects.ObjectParameterCollection
-> 00000071f6ce7ad0 System.Collections.Generic.List`1[[System.Data.Objects.ObjectParameter, System.Data.Entity]]
-> 00000071f6ce7af8 System.Object[]
-> 00000071f8273b80 System.Data.Objects.ObjectParameter
-> 00000071f826d2f0 System.String
EF を使用したデータコンテキストがどこかに固定されているようです。問題は、どこで、なぜ?私の webapp は ef 呼び出しでいっぱいです。