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

后端 未结 7 1311
梦谈多话
梦谈多话 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:36

    Just additional to the other points; if you want access to a dirty amount of memory, consider x64 - but be aware that the maximum single object size is still 2GB. And because references are larger in x64, this means that you actually get a smaller maximum array/list size for reference-types. Of course, by the time you hit that limit you are probably doing things wrong anyway!

    Other options:

    • use files
    • use a database

    (obviously both has a performance difference compared to in-process memory)


    Update: In versions of .NET prior to 4.5, the maximum object size is 2GB. From 4.5 onwards you can allocate larger objects if gcAllowVeryLargeObjects is enabled. Note that the limit for string is not affected, but "arrays" should cover "lists" too, since lists are backed by arrays.

提交回复
热议问题