0

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?

Vinodh
  • 385
  • 1
  • 4
  • 15

1 Answers1

0

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 ;
     }
Graffito
  • 1,658
  • 1
  • 11
  • 10
  • 1
    GC.Collect cannot help with out of memory exception. It is called by infrastructure when memory is closed to threshold. GC.Collect can be useful when you know moments in your application of low processor consummation. in this case you can utilize it with more efficiency. – Kirill Bestemyanov Jun 21 '15 at 19:57
  • GC.collect does help if there is a lot of non contiguous memory allocations to be freed. In thiscase, the virtual free space can be significantly higher than Threshold, but an allocation of a large array - with a size under free space - may fail because the system won't find the required amount of contiguous space. – Graffito Jun 23 '15 at 18:46