Out Of memory Exception in IIS

2019-01-29 08:34发布

I have have an application that has MVC template and uses REST . Say I have a rest call made and it hits the particular method

    void sample function() {
   // connects to db through entity framework
   // retrieves data and embeds in to list
   //returns JSON of data received.
   }

So the problem here is I measured the memory it took to run the program . it was about say 40,000kb. Now when i give another rest call the memory is not cleaned in IIS.It starts from 40,000kb instead of zero.finally if i make like 3 or 4 calls there is Out of Memory Exception. So after every call i need the IIS memory to be cleaned up,instead it retains the memory for the previous call. How can i release memory for all the previous calls made.I have tried various solution by disposing model and all other possibilities. The solution seem to Work if deployed on local instead of IIS. Can some one please help me?

1条回答
乱世女痞
2楼-- · 2019-01-29 08:56

If garbage collection is the solution, a simple GC.Collect is often unsufficient and, for performance reason, it should only be called if really required. Try the following procedure that calls the garbage when the available memory is too low (below the threshold provided as procedure parameter).

internal static void CollectGarbage(int SizeToAllocateInMo)
{
       long [,] TheArray ;
       try { TheArray =new long[SizeToAllocateInMo,125000]; }low function 
       catch { TheArray=null ; GC.Collect() ; GC.WaitForPendingFinalizers() ; GC.Collect() ; }
       TheArray=null ;
     }
查看更多
登录 后发表回答