设置最大内存使用C# [英] Set Maximum Memory Usage C#

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

问题描述

我有必须使用我没有写,我没有改变它的功率库的应用程序。基本上有内存泄漏,所以长它运行,它越泄漏;它基本上只是写道,我没有删除的权力陈旧页面文件。内存泄漏实际上并没有引起程序崩溃,它只是简单地吃了所有的记忆。当使用所有系统的memeory,操作系统将刚开始删除旧的页面文件,一切都正常运行。

I have an application that must use a library that I didn't write and I don't have the power to change it. Basically there is a memory leak, so the long it runs, the more it leaks; it basically just writes stale pagefiles that I don't have the power to delete. The memory leak doesn't actually cause the program to crash, it just simply eats up all the memory. When it is using all the system's memeory, the OS will just start deleting the old page files and everything runs fine.

如果我一个2GB的系统上运行我的应用程序,它会使用2 GB和继续运行;同为16GB的系统。

If I run my app on a 2gb system, it will use 2 gb and continue to run; same for a 16gb system.

有没有办法来设置内存的应用程序可以使用的金额是多少?

Is there a way to set the amount of memory an application can use?

推荐答案

这是一个每个进程限制在Windows中。每个过程在一个32位机得到〜2GB虚拟地址空间(这就是堆利用的)。恐怕没有什么可以做这件事。

That is a per-process limitation in Windows. Each process gets ~2GB virtual address space (that is what Heap makes use of) in a 32-bit machine. And I am afraid there is not much you can do about it.

粗略地说,CLR能够保持高达内存中的对象〜1.6GB。这应该是足以满足大多数的应用程序。如果没有,那么你需要在你的应用程序。

Roughly, CLR is able hold upto ~1.6GB of objects in memory. That should be enough for most of the applications. If not, then you need to work on your application.

在我的情况,我遇到了类似的问题,然后使用SqlDataReader的获取在指定的块大小的物体,过程它,计算它,从内存中清除它,然后再取另一块

In my case, I faced a similar problem and then used SqlDataReader to fetch objects in a specified chunk size, process it, compute it, clean it from memory, and then fetch another chunk.

还有MSDN上详细的文章 - 调查内存问题

There is also a detailed article on MSDN - Investigating Memory Issues

希望这将是有益的。

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

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