应用程序在启动时使用超过1GB RAM
我已经从事此应用程序已经有一段时间了,但它几乎完成了,所以我决定开始修复一些诸如高内存使用之类的东西。
我正在使用Visual Studio 2022,并且是.NET帧4.8 C#形式应用程序。在表格上,我有几个页面控件,每个控件都有2-5个选项卡。我有几个分开的面板容器,所有这些容器都有按钮,标签和文本框。我在全球宣布的最小变量(总共6个),我尝试在本地声明所有变量。我有1堂课。
在启动时,诊断工具显示该应用程序使用1,2GB的RAM。在任务管理器中,它还表明它正在使用约1,2GB的RAM。我使用gc.collect()
将其降至550g。有什么方法我仍然可以降低RAM使用情况还是正常?如果我没有提供足够的信息,请告诉我,我会尽我所能。
编辑:感谢Juanjo,Joe Sewell和Hans Passant解决了问题。
我有数百个一次性组件。还没有完成所有操作,但这会让我降低到550MB ISH RAM的使用情况。我确实有一个小数据库,但是在程序开始时没有连接它。使RAM从550MB变为29MB的最后一个问题是我没有使用的图像列表中的一些图像。感谢您的三个帮助,从1,2GB到29MB。
I've been working on this application for a while now and it's nearly finished so I decided to start fixing some stuff like the high memory usage.
I'm using Visual Studio 2022 and it's .NET Framwork 4.8 C# Form application. On the form I have a few page controls each with 2-5 tabs. I have a few split panel containers and all of them have buttons, labels and text boxes. I have minimal variables declared globally (6 in total), I tried declaring all variables locally. I have 1 extra class.
On startup, the Diagnostics tool shows that the application is using 1,2GB of RAM. In task manager, it also shows it's using around 1,2GB of RAM. I've gotten this down to 550G using GC.Collect()
. Is there a way I can still lower the RAM usage or is it normal? If I didn't give enough information let me know and I'll give what I can.
Edit: Thanks to Juanjo, Joe Sewell and Hans Passant the problem has been solved.
I have hundreds of disposable components. Haven't done all of them but that would get me down to 550MB ish RAM usage. I did have a small database but it wasn't being connected at the start of the program. The last problem that made the RAM go from 550MB to 29MB was a few images inside an image list I had that wasn't used. Thanks to you three for the help, from 1,2GB to 29MB.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可以是什么。没有项目并调试,很难知道。但是,
gc.collect()
将其降至一半,因为很少有情况需要调用gc.collect()
使我怀疑您是否怀疑您正在使用idisposable
组件,并且您没有调用dispose()
。查看您使用的某些对象,如果它们具有
dispose()
方法,并且如果它们确实使用使用c#的模式在使用它们完成后处理这些对象。我希望它有帮助。同样,没有项目很难知道。
This can be anything. Without the project and debugging it is hard to know. Nontheless,
GC.Collect()
bringing it down to half, knowing that there are very few cases where you need to callGC.Collect()
makes me to suspect that you are usingIDisposable
components and you are not callingDispose()
.Look at some of the objects you are using if they have the
Dispose()
method and if they do use the using pattern for C# to dispose those objects when you are done with them.I hope it helps. Again without the project it is hard to know.