问题描述
我们正在开发一个大的.Net Windows窗体应用程序。我们正面临着内存泄漏/使用问题,尽管我们正在处理的形式。
We are developing a big .Net Windows Forms application. We are facing memory leak/usage problem in that despite we are disposing the forms.
情景是这样的:
- 在我们的应用程序使用的 60K 的内存,记录显示在网格列表中。
- 当一个记录用户点击它会打开一个表格
myform.showDialog
,显示细节。内存跳 STRONG>从 60〜105M - 现在,我们关闭窗体
MyForm的
返回到电网,和处置的形式和设置为null 。内存的仍在 105M - 现在,如果我们再次执行步骤2,它会从 105M 跳转到 150M 等。
- Our application is using 60K of memory with list of records displaying in a Grid.
- When user click on a record it opens a form
myform.showDialog
, show the details. Memory jumps from 60 to 105M - Now we close the form
myform
to get back to grid, and dispose that form and set it to null. Memory remains at 105M. - Now if we again perform step 2, it would jump from 105M to 150M and so on.
有没有人告诉我们如何释放内存当我们关闭myForm的?任何帮助在这方面将是非常美联社preciated。我们已经尝试过 GC.Collect的()
等,但没有结果。
Can some one tell how can we free up the memory when we close the myForm? Any help in this regard would be highly appreciated. We have already tried GC.Collect()
etc. but no result.
推荐答案
查找泄漏的第一个地方是在事件处理,而不是缺少的Dispose()
通话。说你的容器(父窗体)加载子窗体,并增加了一个处理程序中的子窗体的事件( ChildForm.CloseMe
)。
The first place to look for leaks is in event-handling rather than missing Dispose()
calls. Say your container (the parent form) loads a child form and adds a handler for an event of that child form (ChildForm.CloseMe
).
如果子窗体的目的是从内存中,然后该事件处理程序必须在它被移除清除的垃圾回收的候选人。
If the child form is intended to be cleared from memory then this event handler must be removed before it is a candidate for garbage collection.
这篇关于在WinForms应用程序内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!