C# 数组、HashSet等内存耗尽的解决办法

2022-11-13,,,,

在C#中,如果数据量太大,就会出现 'System.OutOfMemoryException' 异常。

解决办法来自于Stack Overflow和MSDN    https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/gcallowverylargeobjects-element

1.生成改为x64,即让程序运行在64位模式下(任务管理器里可以看到是否是32位的)。

2.配置文件添加<gcAllowVeryLargeObjects enabled="true|false" />

具体位置:<configuration> Element
<runtime> Element
<gcAllowVeryLargeObjects> Element

经过测试,确实没有再出现OutOfMemory的异常

C# 数组HashSet内存耗尽的解决办法的相关教程结束。

《C# 数组、HashSet等内存耗尽的解决办法.doc》

下载本文的Word格式文档,以方便收藏与打印。