簡體   English   中英

System.OutOfMemoryException ASP Net MVC

[英]System.OutOfMemoryException asp net MVC

當代碼涉及到這一部分時,我得到了異常:

[GridAction]
        public JsonResult _ForRisk()
        {
            var user = current.CurrentUser;            
            var applications = from c in appRepository.GetAll().PendingForRisk(user)
                                   let client = c.Clients.FirstOrDefault(t => t.MainOwner == (int)RelationType.Borrower)                                   
                                   let timing = c.Timings.Where(t => t.ApplicationID == c.ID && t.Status == (int)AppStatus.Commited).OrderByDescending(t => t.Date).Take(1).FirstOrDefault()
                                   select new ApplicationViewModelScreen
                                   {
                                       ApplicationID = c.ID,
                                       Branch = c.Branch.Name,
                                       CompanyName = client != null ? client.CompanyName : "",
                                       CompanyRegisterNr = client != null ? client.CompanyRegistrationNo : "",
                                       DecisionStatus = c.ApplicationStatus,
                                       CreateDate = c.RegistrationDate,
                                       Submissiondate = timing != null ? timing.Date : new DateTime?(),
                                       Inputer = c.User.Name + " " + c.User.Surname,
                                    FincAssignedOfficer = c.AssignedOfficerForFinanc != null ? c.AssignedOfficerForFinanc.Name + " " + c.AssignedOfficerForFinanc.Surname : "",
                                    CRMAssignedOfficer = c.AssignedOfficerForCRM != null ?  c.AssignedOfficerForCRM.Name + " " + c.AssignedOfficerForCRM.Surname : "",
                                    CRMIndustry = client.CRMIndustyCode.Description

                                   };
            var data = applications.ToList();

                return Json(new GridModel<ApplicationViewModelScreen>
                {
                    Data = data,
                    Total = data.Count()
                }, JsonRequestBehavior.AllowGet);
        }

(我將StructureMap用作DI,並注入到控制器中)

public ApplicationController(
            IApplicationRepository _appRepository,
            IService<Application> _applicationService, 
            ITargetRepository _targetRepository, 
            IIDGenerator _idGen,
            ICurrent _current,
            IProductRepository _productRepository,
            IUserRepository _userRepository,
            IDecisionReasonRepository _decisionReason,
            IInformation _information,
            IDecisionExceptionRepository _decisionExceptionRepository,
            ITimingRepository _timingRepository,
            ITimingDecisionRepository _timingDecisionRepository)
        {
            current = _current;
            idGen = _idGen;
            appRepository = _appRepository;
            applicationService = _applicationService;
            targetRepository = _targetRepository;
            productRepository = _productRepository;
            userRepository = _userRepository;
            decisionReason = _decisionReason;
            information = _information;
            decisionExceptionRepository = _decisionExceptionRepository;
            timingRepository = _timingRepository;
            timingDecisionRepository = _timingDecisionRepository;
        }

例外

System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
   at System.Collections.BitArray.set_Length(Int32 value)
   at System.Data.Query.InternalTrees.VarVec.Align(VarVec other)
   at System.Data.Query.InternalTrees.NodeInfoVisitor.Visit(FilterOp op, Node n)
   at System.Data.Query.InternalTrees.FilterOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
   at System.Data.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
   at System.Data.Query.InternalTrees.NodeInfoVisitor.RecomputeNodeInfo(Node n)
   at System.Data.Query.InternalTrees.Node.InitializeNodeInfo(Command command)
   at System.Data.Query.InternalTrees.Node.GetExtendedNodeInfo(Command command)
   at System.Data.Query.InternalTrees.NodeInfoVisitor.Visit(ProjectOp op, Node n)
   at System.Data.Query.InternalTrees.ProjectOp.Accept[TResultType](BasicOpVisitorOfT`1 v, Node n)
   at System.Data.Query.InternalTrees.BasicOpVisitorOfT`1.VisitNode(Node n)
   at System.Data.Query.InternalTrees.NodeInfoVisitor.RecomputeNodeInfo(Node n)
   at System.Data.Query.InternalTrees.Node.InitializeNodeInfo(Command command)
   at System.Data.Query.PlanCompiler.TransformationRulesContext.PreProcessSubTree(Node subTree)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.InternalTrees.RuleProcessor.ApplyRulesToSubtree(RuleProcessingContext context, ReadOnlyCollection`1 rules, Node subTreeRoot, Node parent, Int32 childIndexInParent)
   at System.Data.Query.PlanCompiler.TransformationRules.Process(PlanCompiler compilerState, ReadOnlyCollection`1 rulesTable, Boolean& projectionPruningRequired)
   at System.Data.Query.PlanCompiler.TransformationRules.Process(PlanCompiler compilerState, TransformationRulesGroup rulesGroup)
   at System.Data.Query.PlanCompiler.PlanCompiler.Compile(List`1& providerCommands, ColumnMap& resultColumnMap, Int32& columnCount, Set`1& entitySets)
   at System.Data.EntityClient.EntityCommandDefinition..ctor(DbProviderFactory storeProviderFactory, DbCommandTree commandTree)
   at System.Data.EntityClient.EntityProviderServices.CreateCommandDefinition(DbProviderFactory storeProviderFactory, DbCommandTree commandTree)
   at System.Data.EntityClient.EntityProviderServices.CreateDbCommandDefinition(DbProviderManifest providerManifest, DbCommandTree commandTree)
   at System.Data.Common.DbProviderServices.CreateCommandDefinition(DbCommandTree commandTree)
   at System.Data.Objects.Internal.ObjectQueryExecutionPlan.Prepare(ObjectContext context, DbQueryCommandTree tree, Type elementType, MergeOption mergeOption, Span span, ReadOnlyCollection`1 compiledQueryParameters)
   at System.Data.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
   at System.Data.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Objects.ObjectQuery`1.System.Collections.Generic.IEnumerable<T>.GetEnumerator()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Corporate.Presentation.MVC.Controllers.ApplicationController._ForRisk() in K:\TempProjects\CorporateAPS\Corporate.Presentation.MVC\Controllers\ApplicationController.cs:line 220
   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.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
   at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14()
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName)
   at System.Web.Mvc.Controller.ExecuteCore()
   at System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext)
   at System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<>c__DisplayClassb.<BeginProcessRequest>b__5()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.<MakeVoidDelegate>b__0()
   at System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End()
   at System.Web.Mvc.MvcHandler.<>c__DisplayClasse.<EndProcessRequest>b__d()
   at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
   at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
   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.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
        Logged on Wednesday, March 28, 2012 at 3:47:20 PM

該行:

appRepository.GetAll().PendingForRisk(user)

正在將大概很多行加載到內存中。 此外,接下來的兩行使情況更糟:

let client = c.Clients.FirstOrDefault(t => t.MainOwner == (int)RelationType.Borrower)                                   
let timing = c.Timings.Where(t => t.ApplicationID == c.ID && t.Status == (int)AppStatus.Commited).OrderByDescending(t => t.Date).Take(1).FirstOrDefault()

對於每個單獨的appRepository項目,你正在評估ClientsTimings ,為此,還可能有許多元素。 這些可能是延遲加載的,並將所有更多對象帶入內存。 簡而言之,例外很明顯-您一次將太多對象加載到內存中。

不幸的是,在不知道appRepository實際上是什么(Linq-to-Sql,Entity Framework等)的情況下,很難提供任何有關如何改進代碼的提示。 appRepository.GetAll().PendingForRisk(user)的返回類型是什么?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM