Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从未调用Ninject.MVC5发布范围-OutOfMemoryException_Ninject_Ninject.web.mvc - Fatal编程技术网

从未调用Ninject.MVC5发布范围-OutOfMemoryException

从未调用Ninject.MVC5发布范围-OutOfMemoryException,ninject,ninject.web.mvc,Ninject,Ninject.web.mvc,我是Ninject的新手,但我已经确信Ninject.MVC5 NuGet包的开箱即用配置实际上从未释放作用于HttpContext的对象。在我的一些较大的报告反复使用大量内存之后,我始终会出现OutOfMemoryException 所以为了证明我没有失去理智,我创建了一个空的测试项目。我在VS2017中通过文件->新建项目->C#->Web->ASP.NET Web应用程序->MVC(在模式中)创建了一个默认项目。这也是一个新的解决方案,很清楚。然后我安装了Ninject 3.2.2(不是最

我是Ninject的新手,但我已经确信Ninject.MVC5 NuGet包的开箱即用配置实际上从未释放作用于HttpContext的对象。在我的一些较大的报告反复使用大量内存之后,我始终会出现OutOfMemoryException


所以为了证明我没有失去理智,我创建了一个空的测试项目。我在VS2017中通过文件->新建项目->C#->Web->ASP.NET Web应用程序->MVC(在模式中)创建了一个默认项目。这也是一个新的解决方案,很清楚。然后我安装了Ninject 3.2.2(不是最新版本;请仔细查看Ninject.Web.Common nuget包的版本

如果小于3.2.2,这就是问题的原因


Wow,这在2014年得到了修复。当我安装Ninject.MVC5时,我安装了最新的非测试版。我想NuGet会自动删除Ninject.Web.Common和Ninject.Web.Common.WebHost的版本,这些版本在Ninjuct.MVC5 3.2.1出现之前就已经存在了。这只是一个有根据的猜测,但这是我唯一能解释安装它的方法一周前,从2014年开始获得版本。Thx!
public class MemoryEater : IDisposable
{
    public List<int> _nums = new List<int>();

    public MemoryEater()
    {
        var rand = new Random(); // Use random so that I get a bit of CPU usage I can see in Task Manager
        for (int cnt = 0; cnt < 2_500_000; ++cnt)
        {
            var key = rand.Next();
            _nums.Add(key);
        }
    }

    public void Dispose()
    {
        if (_nums != null)
            _nums = null;
    }
}
public class HomeController : Controller
{
    readonly MemoryEater _me;

    public HomeController(MemoryEater me)
    {
        _me = me;
    }
    private static void RegisterServices(IKernel kernel)
    {
        kernel.Bind<MemoryEater>().ToSelf().InRequestScope();
    }    
    public void DeactivateInstancesForCurrentHttpRequest()
    {
        if (this.ReleaseScopeAtRequestEnd)
        {
            var context = HttpContext.Current;
            this.MapKernels(kernel => ClearCacheOfContext(kernel, context)); // BREAKPOINT A
        }
    }

    private void ClearCacheOfContext(IKernel kernel, HttpContext context)
    {
        kernel.Components.Get<ICache>().Clear(context); // BREAKPOINT B
    }