简体   繁体   English

VB.Net 3.5 MDI应用程序-使用N个内存后,MDIChild表单停止打开

[英]VB.Net 3.5 MDI Application - MDIChild forms stop opening after N memory has been used

I hope someone may be able to help! 希望有人可以提供帮助!

We have a pretty large VB.Net MDI application that has been converted from VB6. 我们有一个很大的VB.Net MDI应用程序,它已从VB6转换而来。 When it is first run up with no MDIChild forms opened it uses about 35,000K. 在没有打开MDIChild表单的情况下第一次运行它时,它使用了大约35,000K。 As more and more forms are opened (but not closed) the memory usage (according to Task Manager) creeps up at approximately 4,000K per form. 随着越来越多的表单被打开(但没有关闭),每张表单的内存使用量(根据任务管理器)逐渐增加到大约4,000K。 (I am aware that TM only shows allocated memory for the application, and not the actual memory used.) (我知道TM仅显示为应用程序分配的内存,而不显示实际使用的内存。)

The issue is that when the allocated memory reaches a certain point, which is different depending upon what the available memory is on the target machine, no more forms can be opened until one or more of the open forms are closed. 问题在于,当分配的内存达到某个特定点(取决于目标计算机上的可用内存不同)时,在关闭一个或多个打开的窗体之前,无法再打开任何窗体。 The "limit" of the ammount of forms that can be opened seems to depend upon the available memory of the machine. 可以打开的表格数量的“限制”似乎取决于机器的可用内存。

For example: - On a virtual machine with only 512M for the whole machine it appears to be about 7-8 forms and the allocated memory is around 80,000K when this happens. 例如:-在整个计算机只有512M的虚拟机上,它看起来大约有7-8个表格,并且发生这种情况时分配的内存大约为80,000K。 - On our terminal server machine which has 3GB and is also running various other thirsty applications it stops at around 20+ forms and a memory allocation of about 100,000 - 105,000K. -在我们的终端服务器计算机上,该计算机具有3GB的内存,并且还运行着其他各种口渴的应用程序,它停止在20多种形式左右,并且内存分配约为100,000-105,000K。

I have tried using perfmon to see if there is a leak and that is indicating steady usage. 我尝试使用perfmon来查看是否存在泄漏,这表明使用稳定。

However, even if I close the forms the allocated memory only drops by about 3000K for the first form closed and then 100K for each form closed after. 但是,即使我关闭表单,分配的内存对于第一个关闭的表单也只会减少大约3000K,然后为每个关闭的表单减少100K。 If I then add a few more forms the memeory increases, and if I then close some the same -3000K, -100K meomry reduction pattern happens again. 如果再添加更多形式,则内存增加,如果再关闭相同的-3000K,则-100K内存减少模式再次发生。

Has any one come accross this before? 以前有人来过吗? Can any one please help as this is looking like a bit of a show stopper! 任何人都可以帮忙,因为这看起来有点像表演障碍! I look forward to your replies. 我期待您的答复。

Incidentally the original VB6 version does not have this issue and also will return it's memory allocation to that it started with if you close each form rather than the allocation gradually creeping up because teh app releases less than it is allocated. 顺便说一句,原始的VB6版本不存在此问题,并且如果您关闭每个表单,它也会将其内存分配返回到其开始时的分配,而不是逐渐分配,因为该应用发布的版本少于分配的版本。

EDIT: I have just managed to get the same error while in dev. 编辑:我刚刚设法在开发中得到相同的错误。 It appears that a WIN32Exception is being thrown in a UserControl. 似乎在UserControl中引发了WIN32Exception。 The error is "Error creating window handle." 错误是“创建窗口句柄时出错”。

Thanks and kind regards, Duane. 谢谢您,杜安。

Your app is simply consuming the quota of handles that Windows imposes. 您的应用只是在消耗Windows施加的句柄配额。 By default it is 10,000 handles, trying to create another window will fail with "Error creating window handle". 默认情况下,它是10,000个句柄,尝试创建另一个窗口将失败,并显示“错误创建窗口句柄”。

Maybe those limits are lower for a VM or TS install, not sure. 不确定,对于VM或TS安装,这些限制可能较低。 The upper limit is rather enormous and you should never have any trouble staying far away from it. 上限相当大,远离它应该没有任何麻烦。 In Task Manager, use View + Select Columns and tick USER objects, GDI object and Handles. 在任务管理器中,使用“查看+选择列”,然后勾选“用户”对象,“ GDI”对象和“句柄”。 Any of these columns growing without bound is a sure sign of a bug in your code, like not disposing forms or controls. 这些列中的任何一个都可以无限制地增长,这肯定是代码中有错误的迹象,例如不处理表单或控件。 Consuming more memory is a side-effect of this leak. 消耗更多的内存是此泄漏的副作用。

事实证明,在释放USER对象之前,我们需要在自定义UserControls中显式处置每个控件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM