.NET WinForm内存消耗 [英] .NET WinForm Memory Consumption

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

问题描述

我一直在使用".NET Memory Profiler"对WinForm的应用程序进行性能分析.

I've been profiling a WinForm's application using ".NET Memory Profiler".

根据Windows任务管理器的说法,我似乎不太了解我的应用程序是如何增长到1GB,2GB,然后3GB的.

I can't quite seem to understand how my application is growing to 1GB, then 2GB, then 3GB of usage - according to windows task manager.

使用该工具的专用字节,所有堆中的总字节数"仅显示为70MB左右.在我周围徘徊的实例列表的顶部,它们主要是String或对许多小对象的WeakReferences.

The private bytes using that tool, and "Total Bytes in All Heaps" shows only as 70MB or so. At the top of my list of instances hanging around, they are mostly String, or WeakReferences to lots of little objects.

应用程序正在做的所有工作都是显示一种从数据库加载数据的表单.我重复表格的显示/处理周期约100次,并且增长是连续的.

All the application is doing is showing a form that loads data from a database. I repeat the show/dispose cycle of the form about 100 times and the growth is continuous.

我现在已经尝试了大约3种内存分析工具,但没有一个工具向我展示了这种大量内存消耗的来源.

I've tried about 3 memory profiling tools now and none of them are showing me where this enormous amount of memory consumption is coming from.

任何人都可以帮忙或猜测一下可能是什么吗?

Can anyone help or take a guess as to what it might be?

谢谢.

推荐答案

这是VB.NET应用程序的已知问题吗?

Is this a known issue for VB.NET apps?

是的.这是编译为可执行文件的编辑+继续"支持的副作用.它受WithWiths关键字声明的任何事件的影响. WeakReference跟踪这些事件实例.问题是,如果您在没有调试器的情况下运行该应用程序,则这些WeakReferences将被泄漏.进程占用内存的速度高度取决于创建该类的实例的数量.每个对象的每个事件的泄漏为16个字节.

Yes. It is a side-effect of Edit + Continue support compiled into the executable. It is affected by any event that is declared with the WithEvents keyword. A WeakReference keeps track of those event instances. Problem is, those WeakReferences are leaked if you run the app without a debugger. The rate at which the process consumes memory is highly dependent on how many instances of the class get created. The leak is 16 bytes per event per object.

解决方法很简单,请在没有调试器的情况下不要使用您应用的Debug版本.仅使用发布版本.当然,仅将发布版本发送给您的客户.

The workaround is simple, do not use the Debug build of your app without a debugger. Only use the Release build. And of course, only ship the Release build to your customer.

这篇关于.NET WinForm内存消耗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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