C#:内存异常 [英] C# : Out of Memory exception

查看:166
本文介绍了C#:内存异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天今天我的应用程序抛出了 OutOfMemoryException异常。对我来说这一直是几乎是不可能的,因为我有4GB内存和大量的虚拟内存了。当我试图现有集合添加到一个新的列表发生错误。

Today my application today threw an OutOfMemoryException. To me this was always almost impossible since I have 4GB RAM and a lot of virtual memory too. The error happened when I tried to add an existing collection to a new list.

List<Vehicle> vList = new List<Vehicle>(selectedVehicles);  

据我了解这里没有分配,因为我的车新名单应该包含已内存里面存在的内存。我不得不承认是一个非常复杂的类,我试图约50.000项目一次添加到新名单。但是,由于所有的汽车■在应用程序来自于仅在大小200MB数据库:我不知道,可能会导致 OutOfMemoryException异常在这一点上。

To my understanding there isn't much memory allocated here since the vehicles my new list should contain already exist inside the memory. I have to admit Vehicle is a very complex class and I tried to add about 50.000 items to the new list at once. But since all Vehicles in the application come from a database that is only 200MB in size: I have no idea what may cause an OutOfMemoryException at this point.

推荐答案

两点:


  1. 如果您运行的是32位Windows,你不会有所有的访问4GB,2GB仅

  2. 请不要忘记,列表的底层实现是一个数组。如果你的内存是大量碎片,可能没有足够的连续空间分配给你的列表,即使在总你有足够的可用内存。

  1. If you are running a 32 bit Windows, you won't have all the 4GB accessible, only 2GB.
  2. Don't forget that the underlying implementation of List is an array. If your memory is heavily fragmented, there may not be enough contiguous space to allocate your List, even though in total you have plenty of free memory.

这篇关于C#:内存异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆