none
Failed to allocate a managed memory buffer of 268435456 bytes. The amount of available memory may be low RRS feed

  • Question

  • Hi,

    On my Dev PC I'm running into a InsufficientMemoryException calling a WCF service from a separate process. In this case the service is running under IIS Express locally.

    I'm running in buffered mode, but I'm just trying to figure out exactly where/what this limit is. I have all the usual suspects maxed out in the web.config. I'm running in buffered mode, but I don't want to switch to streaming. Really I'm just trying to figure out what limit I'm hitting given:

    • The message says it can't allocate a memory buffer of 268435456, i.e. 256MB. Where is this limit of 256MB defined and what does it relate to? I've found other similar questions on this and other forums with both the exact same number (268435456) and with different numbers which makes me wonder where this is defined?
    • The exception is thrown on the client, not in the service.
    • I've looked at the call I'm making and that should be returning approximately 183512087 bytes or 175MB (+headers) which is isn't 256MB. (Edited: I corrected this number as I hadn't taken serialization into account - doh! - I originally had 9046960/8.62MB).

    I'm really just trying to establish exactly what this message is telling me. Is it a general out of memory exception, is it something to do with WCF, is it a limitation of IIS Express?

    Web Binding

        <bindings>
          <basicHttpBinding>
            <binding name="CustomBinding" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" maxBufferPoolSize="2147483647">
              <readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" />
              <security mode="None" />
            </binding>
          </basicHttpBinding>
        </bindings>

    I also have maxItemsInObjectGraph="2147483647" and maxAllowedContentLength="4294967295"

    Client binding

                var securityMode = BasicHttpSecurityMode.TransportCredentialOnly;
    
                var binding = new BasicHttpBinding(securityMode)
                {
                    MaxBufferSize = 2147483647,
                    MaxReceivedMessageSize = 2147483647,
                    SendTimeout = new TimeSpan(0, 0, 30, 0),
                };
    
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;


    As I said I'm not looking for a solution (although that would be nice) and I'm not looking to change to streaming, I'm just trying to understand exactly what is going on here.

    Thanks for your help

    LJ

    Exception

    System.InsufficientMemoryException occurred
      HResult=-2146233027
      Message=Failed to allocate a managed memory buffer of 268435456 bytes. The amount of available memory may be low.
      Source=mscorlib
      StackTrace:
        Server stack trace:
           at System.Runtime.Fx.AllocateByteArray(Int32 size)
           at System.Runtime.InternalBufferManager.PooledBufferManager.TakeBuffer(Int32 bufferSize)
           at System.ServiceModel.Channels.BufferManager.WrappingBufferManager.TakeBuffer(Int32 bufferSize)
           at System.ServiceModel.Channels.MessageEncoder.BufferMessageStream(Stream stream, BufferManager bufferManager, Int32 maxBufferSize)
           at System.ServiceModel.Channels.MessageEncoder.ReadMessage(Stream stream, BufferManager bufferManager, Int32 maxBufferSize, String contentType)
           at System.ServiceModel.Channels.HttpInput.ReadChunkedBufferedMessage(Stream inputStream)
           at System.ServiceModel.Channels.HttpInput.ParseIncomingMessage(HttpRequestMessage httpRequestMessage, Exception& requestException)
           at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)
           at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
           at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)
           at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
           at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
           at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
        Exception rethrown at [0]:
           at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
           at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)





    Friday, May 6, 2016 12:09 PM

Answers

  • Thanks, and a fair comment!

    I was just curious because I've seen a lot of posts about this message (usually WCF related) in but no-one seems to have actually been able to explain exactly what the cause is.

    I removed one column from my call and it went away, but I'm still none the wiser.
    Friday, May 6, 2016 5:08 PM

All replies

  • Really I'm just trying to figure out what limit I'm hitting given:

    is it something to do with WCF, is it a limitation of IIS Express?

    The best thing you can do to just eliminate this whole thing is to use local IIS, the real one, on your local machine. Local IIS is where it counts and not IIS Express, because if it doesn't work on local IIS, then you should consider that you have a problem.

     

    Friday, May 6, 2016 4:37 PM
  • Thanks, and a fair comment!

    I was just curious because I've seen a lot of posts about this message (usually WCF related) in but no-one seems to have actually been able to explain exactly what the cause is.

    I removed one column from my call and it went away, but I'm still none the wiser.
    Friday, May 6, 2016 5:08 PM
  • Hello,

    I am glad to know that you have solved your problem by yourself.

    >>Failed to allocate a managed memory buffer of 268435456 bytes. The amount of available memory may be low

    The above message is the memory exception. When meeting the above exception, we need to check if the machine has enough physical memory available and the number of requests that are processed.

    In the default buffered-transfer mode, a message must be completely delivered before a receiver can read it. In the Streamed transfer mode, the receiver can begin to process the message before it is completely delivered. The Streamed mode is useful when the information that is passed is lengthy and can be processed serially. Streaming mode is also useful when the message is too large to be entirely buffered.

    For more information, please try to refer to the following article:
    http://msdn.microsoft.com/en-us/library/ms789010.aspx .

    Best Regards,
    Amy Peng


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.




    Tuesday, May 10, 2016 6:06 AM
    Moderator