内存不足异常未得到处理 [英] Out of memory exception was unhandled

查看:81
本文介绍了内存不足异常未得到处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



任何人都可以告诉我为什么在Windows窗体平台上加载一个新窗体时会出现这种异常。我有2个表单,所以从form1我传递几个数据到form2并尝试加载表单但我得到这个例外。在form2中,我有27个标签,29个矩形,2个datagridview表和6个按钮。是,这些许多控件对系统来说太过分了......?如何解决问题..?在此先感谢..

Hi all,

Can anybody tell me why do i get such exception when a new form is loaded with controls in windows form platform. I have got 2 forms, so from form1 i am passing few data to form2 & trying to load the form but i get this exception. In form2 i have 27 labels, 29 rectangles, 2 datagridview tables & 6 buttons. Is, these many controls too much for the system to hanlde...? How to resolve the issue..? Thanks in advance..

推荐答案

它与表单上的控件数量无关。你很可能正在创建新的绘图对象(笔,画笔,图形......),并且在你使用它们时不会将它们丢弃。



您可以获得OutOfMemory异常,其原因有很多,而且与内存无关。在你的情况下,这可能是因为你的代码中有句柄泄漏。



打开任务管理器,单击进程选项卡,然后添加列处理到显示屏。启动您的应用程序并在进程列表中查找它。在使用该应用程序时,请查看句柄编号。如果它开始超过几千个句柄,你的代码中就会出现泄漏,最终导致OutOfMemory异常。
It has nothing to do with the number of controls on your form. It''s more than likely you''re creating new drawing objects (Pen, Brush, Graphics, ...) and not disposing them when you''re done using them.

You can get "OutOfMemory" exceptions for a number of reasons that don''t have anynthing to do with memory. In your case, it''s probably because you have a "handle" leak in your code.

Open Task Manager, click on the Processes tab, then add the column "Handles" to the display. Start your app and look for it in the Processes list. Watch the Handles number as you use the app. If it starts to exceed a couple thousand handles, you''ve got a leak in your code that will eventually cause an "OutOfMemory" exception.


当需要时会出现这种类型的错误需要处理的大量数据。因此使用USING关键字在使用对象时处理该对象。
These type of error occur when there are to much data to process.So for that use "USING" keyword which dispose the object when its used.


这篇关于内存不足异常未得到处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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