简体   繁体   English

从IIS内存清除大型对象

[英]Cleaning up large Objects from IIS Memory

I have an application that stores DataTables in an in memory cache (AppFabric). 我有一个将DataTables存储在内存缓存(AppFabric)中的应用程序。 These DataTables can be quite large. 这些数据表可能很大。 Once there is a lot of traffic from our app (MVC site) the memory usage of IIS goes through the roof very quickly. 一旦来自我们的应用程序(MVC站点)的流量很大,IIS的内存使用就会很快通过屋顶。

Ideally we want to be able to release the memory that these DataTables consume once requested from the Cache. 理想情况下,我们希望能够一旦从缓存请求后就释放这些数据表消耗的内存。

The code of the Controller is something along the lines of Controller的代码类似于

Using (DataTable dt = DataTable)
{
    DataTable dt = Cache.GetObject(objectID);

    //perform some manipulation on Data table
    DataTable dtSmaller = dt.Select("Select top 1...");

   dt.Dispose();
}   
    //return from controller
return dtSmaller;

Once this controller is hit many times the W3WP.exe process uses masses of memory until eventually going out of memory. 一旦多次击中该控制器,W3WP.exe进程将使用大量内存,直到最终耗尽内存。 What is happening is that a DataTable comes from the Cache, it's queried to reduce the size of the output data. 发生的情况是DataTable来自缓存,查询它是为了减少输出数据的大小。 I then dispose the original DataTable. 然后,我处置原始的DataTable。

I was looking for a way of releasing the memory consumed by the DataTable without the depending on IIS Garbage Collection 我一直在寻找一种释放数据表消耗的内存的方法,而不必依赖于IIS垃圾回收

You can force a full Garbage Collection cycle by calling GC.GetTotalMemory(true) 您可以通过调用GC.GetTotalMemory(true)强制执行完整的垃圾回收周期。

More info on the method: GC.GetTotalMemory 有关该方法的更多信息: GC.GetTotalMemory

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM