Windows Forms中的数据集构建内存堆 [英] Datasets in Windows Forms building memory heaps

查看:52
本文介绍了Windows Forms中的数据集构建内存堆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Win Forms的新手.我的应用程序会继续建立内存,而不是将其释放回系统.我尝试处理掉所有创建的数据集,并且表单已经关闭和处理.垃圾回收器不知何故没有释放内存.
我使用了内存探查器,发现为数据集构建的查询仍保留在内存中.
我怀疑形成的大型"aaa.xsd"文件会创建巨大的查询字符串-即用户非调试程序代码" ......系统在处理数据集时会生成什么内容.
它们是清除查询字符串的任何方法,我怀疑这是占用内存的原因. 我希望我已经详细提出了这个问题.如果需要,请随时提出更多问题.
感谢您阅读并回复.

I am novice to Win Forms. My application keeps on building up memory and not releasing it back to system. I have tried disposing off all the datasets created and the forms have been closed and disposed. Somehow the Garbage Collector is not freeing up the memory.
I have used the memory profilers and find that the queries build for the datasets are still kept in the memory.
I suspect the big "aaa.xsd" files that are formed to create huge query strings - that are "User Non debugger code"......what system did generate when doing the datasets.
Is their any way to clear off the query strings , that is what I suspect is holding up the memory.
I hope I have put up the question in a detailed fashion. Please feel free to ask more questions if need be.
Thanks for reading this and replying.

推荐答案

如果您正在使用TaskManager,那是您的第一个错误.

您的代码在由.NET CLR(公共语言运行时)管理的一种虚拟机中运行. CLR维护一个托管"内存堆,供您的应用程序使用.该堆已分配到Windows移交的内存之外.

代码运行时,它将开始从托管内存池中分配其对象.如果托管池的可用内存不足,则CLR要求Windows提供更多内存,并将其添加到托管堆中.

任务管理向您显示应用程序已保留的内存,而不是其实际使用的内存!

当您的应用程序释放对象时,内存将返回托管堆,而不是Windows.

.NET CLR在管理内存方面做得非常好.如果Windows需要从CLR返回内存,则CLR非常乐意返回它可以提供的任何内存,这通常是一个相当大的块.

如果要查看代码实际使用了多少内存,请使用PerfMon和.NET内存计数器.
If you''re looking in TaskManager, that''s your first mistake.

Your code runs in a type of virtual machine, managed by the .NET CLR (Common Language Runtime). The CLR maintains a "managed" heap of memory for your application to use. That heap is allocated out of memory handed over by Windows.

When your code runs, it starts allocating its object out of the managed pool of memory. If the managed pool runs low on free memory, the CLR asks Windows for more memory and adds it to the managed heap.

Task Manage is showing you the memory reserved for your application, not what it is actually using!

When your application frees objects, the memory goes back into the managed heap, not back to Windows.

The .NET CLR does a very good job of managing memory. If Windows needs memory back form the CLR, the CLR is more than happy to return whatever memory it can, which is usually a pretty good sized chunk.

If you want to see how much memory your code is really using, use PerfMon and the .NET Memory counters.


我已经使用内存分析器(Redgate ANTS)来分析应用程序. br/> CLR显然没有做正确的事情,就是没有将足够的内存释放到OS中.
Win Forms是否有一个缺陷,即它需要大量内存才能运行?
如果要利用内存,Web Apps会更好??

我几乎尝试了每种优化技术,但内存仍然不断堆积.
I have used a memory profiler (Redgate ANTS) to profile the application.
The CLR is obviously not doing the right thing not releasing enough memory into the OS.
Is it a flaw with Win Forms that it acquires lots of memory to run?
Web Apps are better in case of memory utilisation ??

I hsve tried practically every optimisation technique and the memory still keeps piling up.


这篇关于Windows Forms中的数据集构建内存堆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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