34

How to solve this error ultimately?


Server Error in '/****StatWCF_OData' Application.

Memory gates checking failed because the free memory (373817344 bytes) is less than 5% of total memory.  As a result, the service will not be available for incoming requests.  To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InsufficientMemoryException: Memory gates checking failed because the free memory (373817344 bytes) is less than 5% of total memory.  As a result, the service will not be available for incoming requests.  To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[InsufficientMemoryException: Memory gates checking failed because the free memory (373817344 bytes) is less than 5% of total memory.  As a result, the service will not be available for incoming requests.  To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.]
   System.ServiceModel.Activation.ServiceMemoryGates.Check(Int32 minFreeMemoryPercentage, Boolean throwOnLowMemory, UInt64& availableMemoryBytes) +121924
   System.ServiceModel.HostingManager.CheckMemoryCloseIdleServices(EventTraceActivity eventTraceActivity) +86
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath, EventTraceActivity eventTraceActivity) +883

[ServiceActivationException: The service '/****StatWCF_OData/OData.svc' cannot be activated due to an exception during compilation.  The exception message is: Memory gates checking failed because the free memory (373817344 bytes) is less than 5% of total memory.  As a result, the service will not be available for incoming requests.  To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element..]
   System.Runtime.AsyncResult.End(IAsyncResult result) +650220
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +210733
   System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +282

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929

hkutluay
  • 6,794
  • 2
  • 33
  • 53
Sungam Yang
  • 595
  • 3
  • 7
  • 16

8 Answers8

106

Solution is written in your post.

To resolve this, either reduce the load on the machine or adjust the value of minFreeMemoryPercentageToActivateService on the serviceHostingEnvironment config element.

The easiest way just add this into your web.config

<system.serviceModel> 
    <serviceHostingEnvironment minFreeMemoryPercentageToActivateService="0" />
</system.serviceModel> 

Read more about serviceHostingEnvironment here.

Anyway how @Mr Grok correctly pointed it is an indication that your machine doesn't have enough physical memory and you should figure out why is this happening. It can be a serious problem.

Milan Matějka
  • 2,654
  • 1
  • 21
  • 23
  • 10
    Whilst that would be the easiest, it's worth noting that if your server is under resourced, this error could be an indication that you don't really have enough physical memory on the machine so you could be close to having a bigger problem on your hands. It would be well worth checking resource monitor / task manager to see how much memory is in use. – Mr Grok Sep 27 '13 at 09:17
  • 2
    Wondering why not ~2% instead of 0%? With 0%, doesn't it put every process (possibly critical) on the server in danger of a failed alloc (possibly unhandled)? Oh "free memory" doesn't include virtual (looking at task manager showing free=0 with commit = 8/13)? Can anyone confirm? – crokusek Feb 20 '15 at 19:19
6

I had this problem. Turns out SQL server was using over 29 gb of my available 32 gb.

Check your SQL Server if you have one. MS SQL Sever is designed to take up as much free space as you allow it. You can limit this in the maximum server memory box in the property tabs of the SQL Server.

MarcB
  • 79
  • 1
  • 1
1

I added serviceHostingEnvironment attribute to 0 in web.config.

<system.serviceModel> 
    <serviceHostingEnvironment minFreeMemoryPercentageToActivateService="0" />
</system.serviceModel>

This is the sipmplest way i found of doing this.

user1799669
  • 111
  • 1
  • 3
1

Well I had the same issue and I was looking for the solution. Most of the blogs were suggesting the same solution to add 'serviceHostingEnvironment' attribute in the web.config which is risky job as adding an attribute will effect entire IIS and it's hosted solutions and will restart IIS ultimately.

As error message was related to 'Memory storage issue' and we were asked to reduce the load on the server so what I did is just restarted SQL Server (MSSQLSERVER) service through service manager and everything gets back to normal and I got rid of the memory issue.

Window + R > services.msc > Restart Below Highlighted Service

enter image description here

Waseem Khan
  • 127
  • 1
  • 6
1

Add this to your machine.config under the system.serviceModel section, which will set it for all sites:

<serviceHostingEnvironment minFreeMemoryPercentageToActivateService="0" />

You need Administrator privileges to edit this file.

See this answer on how to find machine.config.

You can check if there are any processes using excess memory before adding this setting. However for me, the default setting did more harm than good because there was a lot of "Standby" memory that was being used that can be ejected by the system when it is needed, so the system was not really out of memory.

0

The web.config worked for me, but also the SQL Server memory was an issue that needed addressed.

I was able to resolve the sql server memory issue without restarting the MSSQL server processes simply by reducing the server properties memory Maximum server memory to a lower value. The default was the effectively unlimited.

Without a MS SQL Service restart, the process automatically started reducing the memory footprint to the configured value.
Screenshot of server properties

George Hix
  • 63
  • 3
0

I tried setting minFreeMemoryPercentageToActivateService="0" in the web.config files, but this still didn't fix in my case. I'm using VMWare and it's performing super slow because I have too many snapshots!! I deleted the old ones, cleaned up some disk space and restarted the server and doing so resolved all the errors.

I'm new to VMWare and SharePoint, thought I could share my experience here!

Kiran Modini
  • 1,184
  • 8
  • 5
-1

You need to restart IIS using the IISReset command-line utility From the Start menu, click Run.

In the Open box, type cmd, and click OK.

At the command prompt, type: iisreset /noforce

IIS attempts to stop all services before restarting. The IISReset command-line utility waits up to one minute for all services to stop.

ararb78
  • 1,137
  • 5
  • 19
  • 44