Tag: 内存不足

C#WCF – 客户端/服务器 – System.OutOfMemoryexception

问题。 使用Net TCP绑定的C#WCF客户端/服务器应用程序(发布者/订阅者模式)。 客户端不断崩溃,出现OutOfMemoryException 。 当我与客户端一起运行任务管理器时,我可以看到内存使用列增加,直到应用程序崩溃。 意图是客户端的多个实例在不同的计算机上运行。 脚本 我有一个客户端/服务器应用程序。 发布者/订阅者设计模式。 在服务器端,有6个组成缓存的字典,每个字典都包含一个自定义对象作为值。 每组字典值每5秒更新一次,作为while循环的一部分。 在5秒循环结束时,将6个字典添加到datacontract对象,每个字典作为不同的数据成员。 然后,数据合同对象通过网络发送到客户端,其中还有6个字典。 然后我循环遍历每个数据协定字典,并根据值是否已存在添加或更新其客户端等效的内容。 摘要 6个字典服务器端。 数据合同中的6个可序列化词典。 6个可绑定的词典客户端。 WCF使用Net TCP Binding通过线路传输数据。 规格 C#.Net 3.5 客户端使用一个DevExpress表单和9个DX网格视图和选项卡控件。 大多数自定义对象都包含“子资产”字典。 – 我已经为这个属性使用了一个可绑定的字典,当你有几百个对象时,我想这会产生开销(虽然我不认为使用可序列化的字典会产生很大的不同,因为它们都包含相同的序列化代码) 。 双方的绑定在开始时以编程方式创建一次,并包含相同的设置(参见下文)。 NetTcpBinding netTcpBinding = new NetTcpBinding(SecurityMode.None); EndpointAddress endpointAddress = new EndpointAddress(EndpoindAddress); InstanceContext context = new InstanceContext(callbackinstance); netTcpBinding.MaxConnections = 5; netTcpBinding.MaxBufferSize = 2147483647; netTcpBinding.MaxBufferPoolSize = 2147483647; […]

如何在C#中打开一个大文本文件

我有一个包含大约100000篇文章的文本文件。 文件结构是: .Document ID 42944-YEAR:5 。日期03 \ 08 \ 11 .Cat政治 文章内容1 .Document ID 42945-YEAR:5 。日期03 \ 08 \ 11 .Cat政治 文章内容2 我想在c#中打开这个文件,逐行处理它。 我试过这段代码: String[] FileLines = File.ReadAllText( TB_SourceFile.Text).Split(Environment.NewLine.ToCharArray()); 但它说: 抛出了类型’System.OutOfMemoryException’的exception。 问题是如何打开此文件并逐行阅读。 文件大小:564 MB(591,886,626字节) 文件编码:UTF-8 文件包含Unicode字符。

ImageList / Image OutOfMemoryException

从ImageList获取图像时,我遇到了OutOfMemoryException,我一直无法找到问题的合适解决方案。 我有一个Custom ListView控件,它附加了一个用于绘制ListViewItems的事件。 然后调用静态方法来绘制项目。 对于大约300个项目的ListView,每次滚动ListView时,我们都会获得大约100Mb的内存。 违规代码已被追踪到以下内容: Image image = item.ImageList.Images[item.ImageKey]; if (image != null) { Size imageOffset = new Size((bounds.Width – image.Width) / 2, 2); Point imagePosition = bounds.Location + imageOffset; graphics.DrawImageUnscaled(image, imagePosition); } 似乎(当然在WinXP上)垃圾收集无法正常工作,导致内存呈螺旋状。 我们已经尝试在代码块之后直接添加一个image.Dispose()来解决问题,但这没有任何影响。 到目前为止,我设法找到的唯一解决方案是在静态方法结束时调用GC.Collect()。 然而,问题在于它会导致ListView缓慢地重新绘制自己,并且在尝试重新绘制时最终会在屏幕上获得工件。 还有其他人经历过这个吗? 或者知道一个解决方法?

抛出了System.OutOfMemoryException – WebClient.DownloadStringAsynch()

我正在编写一个可怜的勒芒负载测试器,我认为我正在正确管理我的资源(线程池)但是当我运行以下代码时,我在调用WebClient.DownloadStringAsynch时得到一个OutOfMemoryException。 使用.net4.0但可以移动到4.5。 问: 修复是什么? 我怎么能使用HttpWebRequest并发送asynch作为webclient的替代? 使用等待使用.net 4.5怎么样(与.net4如何管理带有异步调用的线程有什么不同? static void Main(string[] args) { System.Net.ServicePointManager.DefaultConnectionLimit = 200; while (true) { for (int i = 0; i < 100; i++) { Task.Factory.StartNew(LoadTestAsynchNET40); } Console.WriteLine("…………………….sleeping…………………………."); Thread.Sleep(2); } } static void LoadTestAsynchNET40() { string url = "http://mysrv.com/api/dev/getthis?stuff=thestuff" + "&_=" + DateTime.Now.Ticks; // <— somtimes throws here… using (var client = […]

大数组C#OutOfMemoryException

对于我在C#中的编程练习,我试图创建一个long数组,长度为0x1fffffff(base10中为536,870,911),但是我得到了System.OutOfMEmoryException。 对于构建,我针对x64系统,我在Windows7 x64上运行VisualStudio2008,内存为8GB。 它应该是数组的足够内存(它适用于JDK x64和CPP项目) 有什么想法吗 ? const long MAX = 0x1fffffff; // 536870911 in base10 program.arr = new long[MAX]; for (long i = 0; i < MAX; i++) { program.arr[i] = i; }

如何诊断System.OutOfMemoryException?

我上周五在离开工作之前运行了一些代码,我周一在这里,它以OutOfMemoryException停止。 我估计整个过程需要进行数百亿次计算,所以这不是一项小任务。 我甚至都不知道如何解决这个问题。 有什么指针吗?

如何克服OutOfMemoryException从API中提取大型xml文档?

我从API中提取1M +记录。 pull工作正常,但是当我尝试将ReadToEnd转换为字符串变量时,我遇到了内存ReadToEndexception。 这是代码: XDocument xmlDoc = new XDocument(); HttpWebRequest client = (HttpWebRequest)WebRequest.Create(uri); client.Timeout = 2100000;//35 minutes WebResponse apiResponse = client.GetResponse(); Stream receivedStream = apiResponse.GetResponseStream(); StreamReader reader = new StreamReader(receivedStream); string s = reader.ReadToEnd(); 堆栈跟踪: at System.Text.StringBuilder.ToString() at System.IO.StreamReader.ReadToEnd() at MyApplication.DataBuilder.getDataFromAPICall(String uri) in c:\Users\RDESLONDE\Documents\Projects\MyApplication\MyApplication\DataBuilder.cs:line 578 at MyApplication.DataBuilder.GetDataFromAPIAsXDoc(String uri) in c:\Users\RDESLONDE\Documents\Projects\MyApplication\MyApplication\DataBuilder.cs:line 543 我该怎么做才能解决这个问题?

在c#.net中更新zip时出现内存不足exception

我在尝试在c#.net中的Zip文件中添加文件时遇到OutofMemoryException。 我使用32位架构来构建和运行应用程序 string[] filePaths = Directory.GetFiles(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + “\\capture\\capture”); System.IO.Compression.ZipArchive zip = ZipFile.Open(filePaths1[c], ZipArchiveMode.Update); foreach (String filePath in filePaths) { string nm = Path.GetFileName(filePath); zip.CreateEntryFromFile(filePath, “capture/” + nm, CompressionLevel.Optimal); } zip.Dispose(); zip = null; 我无法理解它背后的共鸣

生成排列时出现System.OutOfMemoryException

我在尝试生成6个字母的排列时收到System.OutOfMemoryException 。 5个字母的排列仍然有效。 这是我用来生成所有排列的代码: private static List getPermutations(int n,string source) { IEnumerable q = source.Select(x => x.ToString()); for (int i = 0; i source, (x, y) => x + y); } return q.ToList(); // THIS IS WHERE THE ERROR HAPPENS } 之后我使用这段代码根据正则表达式过滤它们: private static List filterListByRegex(List list, string regex) { List newList = list.ToList(); for […]