Why am I getting an Out Of Memory Exception in my C# application?

后端 未结 7 1304
梦谈多话
梦谈多话 2020-11-30 00:08

My memory is 4G physical, but why I got out of memory exception even if I create just 1.5G memory object. Any ideas why? (I saw at the same time, in the performance tab of t

相关标签:
7条回答
  • 2020-11-30 00:52

    In a normal 32 bit windows app, the process only has 2GB of addressable memory. This is irrelevant to the amount of physical memory that is available.

    So 2GB available but 1.5 is the max you can allocate. The key is that your code is not the only code running in the process. The other .5 GB is probably the CLR plus fragmentation in the process.

    Update: in .Net 4.5 in 64 bit process you can have large arrays if gcAllowVeryLargeObjects setting is enabled:

    On 64-bit platforms, enables arrays that are greater than 2 gigabytes (GB) in total size. The maximum number of elements in an array is UInt32.MaxValue.

    <configuration>
      <runtime>
        <gcAllowVeryLargeObjects enabled="true" />
      </runtime>
    </configuration>
    
    0 讨论(0)
提交回复
热议问题