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

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

    One more thing to be aware of; some .NET objects require 'contiguous' memory. i.e if you are trying to allocate a large array the system may need not only sufficient free memory in your process but also for all that free memory to be in one big chunk... and unfortunately the process memory gets fragmented over time so this may not be available.

    Some objects/data types have this requirement and some don't... I can't remember which ones do, but I seem to recall StringBuilder and MemoryStream have different requirements.

提交回复
热议问题