OutOfMemoryException,我怀疑原因是DbContext,但是我不确定吗?

时间:2018-09-24 19:13:12

标签: c# entity-framework memory-leaks entity-framework-6 out-of-memory

我们遇到了一个问题,在某个随机的时间点,应用程序将抛出一个outOfMemoryException,我无法在本地本地一致地重现该异常。我使用了Visual Studio中的诊断工具ANTS Memory Profiler,它还创建了一个DUMP文件并对其进行了分析,所有内容似乎都指向在某处创建且未被GC清理的字符串列表。

当我在Visual Studio的诊断工具中查看字符串的实例时,似乎上下文正在创建更多的字符串,并且以某种方式将其链接到DbContext,我不确定100%为什么。另外,当我使用ANTS内存分析器检查实例时,所有字符串似乎都像列db名称,Db MetaData..etc。

enter image description here

任何评论/帮助/建议,将不胜感激。

异常(编辑):

                    Exception type: OutOfMemoryException 
                Exception message: Exception of type 'System.OutOfMemoryException' was thrown.
            at System.Data.SqlClient.TdsParser.TryReadPlpUnicodeChars(Char[]& buff, Int32 offst, Int32 len, TdsParserStateObject stateObj, Int32& totalCharsRead)
            at System.Data.SqlClient.TdsParser.TryReadSqlStringValue(SqlBuffer value, Byte type, Int32 length, Encoding encoding, Boolean isPlp, TdsParserStateObject stateObj)
            at System.Data.SqlClient.TdsParser.TryReadSqlValue(SqlBuffer value, SqlMetaDataPriv md, Int32 length, TdsParserStateObject stateObj, SqlCommandColumnEncryptionSetting columnEncryptionOverride, String columnName)
            at System.Data.SqlClient.SqlDataReader.TryReadColumnData()
            at System.Data.SqlClient.SqlDataReader.TryReadColumnInternal(Int32 i, Boolean readHeaderOnly)
            at System.Data.SqlClient.SqlDataReader.TryReadColumn(Int32 i, Boolean setTimeout, Boolean allowPartiallyReadColumn)
            at System.Data.SqlClient.SqlDataReader.GetString(Int32 i)
            at lambda_method(Closure , Shaper )
            at System.Data.Entity.Core.Common.Internal.Materialization.Coordinator`1.ReadNextElement(Shaper shaper)
            at System.Data.Entity.Core.Common.Internal.Materialization.Shaper`1.SimpleEnumerator.MoveNext()
            at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
            at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
            at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
            at Repositories.AttributeAreaRepository.ActiveAttributesStringForOptions(Int32 builderId, Int32 divisionId, Nullable`1 phasePlanId) in D:\SSSource\Projects\Repositories\AttributeAreaRepository.cs:line 176
            at Web.Areas.Customer.Models.CustomerController.Options(Nullable`1 isSpectOptionTab) in D:\SSSource\Websites\Web\Areas\Customer\Controllers\CustomerController.cs:line 4311
            at Web.Areas.Spec.Controllers.SpecOptionController.Index() in D:\SSSource\Websites\Web\Areas\Spec\Controllers\SpecOptionController.cs:line 35
            at lambda_method(Closure , ControllerBase , Object[] )
            at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
            at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
            at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
            at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
            at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
            at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
            at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
            at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
            at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
            at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
            at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
            at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult)
            at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
            at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
            at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
            at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
            at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
            at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
            at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
            at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
            at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
            at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
            at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
            at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
            at System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller)
            at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
            at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
            at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
            at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)
            at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
            at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
            at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
            at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
            at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
            at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
            at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
            at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
  

Blockquote

0 个答案:

没有答案