Cleaning up large Objects from IIS Memory

寵の児 提交于 2019-12-25 03:52:11

问题


I have an application that stores DataTables in an in memory cache (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.

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

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. What is happening is that a DataTable comes from the Cache, it's queried to reduce the size of the output data. I then dispose the original DataTable.

I was looking for a way of releasing the memory consumed by the DataTable without the depending on IIS Garbage Collection


回答1:


You can force a full Garbage Collection cycle by calling GC.GetTotalMemory(true)

More info on the method: GC.GetTotalMemory



来源:https://stackoverflow.com/questions/25622982/cleaning-up-large-objects-from-iis-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!