c#中的gcAllowVeryLargeObjects和OutOfMemoryException

什么是gcAllowVeryLargeObjects

.net4.5中新增一个配置项 “gcAllowVeryLargeObjects” ,msdn解释如下:

在64位平台上,可以允许总共大于2千兆字节的数组。(2GB)

具体说就是在.net中,List,Arrary, Dictiontry, HashSet, HashTable等列表和数组结构的对象内存可以超过2GB了。 在.net4.5之前,这些对象如果使用内存超过2GB,就会报OutOfMemoryException(内存溢出)错误。

 

如何使用?

***.exe.config文件中 设置如下,如果不存在的话,可以手动创建下。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <gcAllowVeryLargeObjects enabled="true" />
  </runtime>
</configuration>
原文地址:https://www.cnblogs.com/yczz/p/5896346.html