隐藏表单时内存泄漏 [英] Memory leak while Hiding a form

查看:84
本文介绍了隐藏表单时内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有一个主要表格(比如form1)。我想显示另一个表格(比如说

" form2" ;)发生一个事件(比如一个按钮点击),并希望在一段时间后隐藏

,以便在发生

同一事件时再次显示它。我通过创建form2的对象来开发它,并且

通过调用form2.Show()在事件中显示它,并通过调用

form2.Hide()来隐藏它。


问题是,在显示form2时,我的

应用程序的内存使用量增加了很多。在
$期间不会减少b $ b隐藏form2。然后应用程序在事件发生期间每隔一次就会占用内存。


当我尝试form2.WindowState = FormWindowState.Minimized时而不是隐藏它的
,内存使用量会减少。但我的目的是隐藏表单

以便每次事件发生时都会显示

请提出解决此问题的方法。


问候,

Alex

Hello all,

I have a main form(say "form1") .i want to display another form(say
"form2") on occuring of an event (say a button click) and want to hide
it after some time so that it will again displays while occuring of the
same event.I develop it by creating an object of the form2 and
displays it in the event by calling form2.Show() and hide it by calling
form2.Hide().

the problem is that while displaying the form2 the memory usage of my
application increases by a huge amount.it wont decrease during the
hiding of the form2. Then the application eats memory every
times,during the occurnce of the event.

when i tried "form2.WindowState = FormWindowState.Minimized" instead of
hiding it, the memory usage decreases .But my aim is to hide the form
so that it will displays every time the event occurs
please suggest any method for solving this problem.

regards,
Alex

推荐答案

你好Alex,


你可以关闭form2然后每次需要时再显示它吗?


关闭表单将处理其非托管资源,希望释放一些内存。如果它不是那么你可能会遇到更大的问题。


确保你使用的任何非托管组件都在

Dispose方法中释放表格也是如此。


-

Dave Sexton
http://davesexton.com/blog

" Alex" < al ****** @ gmail.comwrote in message

news:11 ********************** @ 42g2000cwt .googlegro ups.com ...
Hi Alex,

Can you Close form2 and then Show it again each time it''s required?

Closing the Form will Dispose of its unmanaged resources, hopefully freeing
up some memory. If it doesn''t then you may have a bigger problem.

Make sure that any unmanaged components that you are using are freed in the
Dispose method of the Form as well.

--
Dave Sexton
http://davesexton.com/blog

"Alex" <al******@gmail.comwrote in message
news:11**********************@42g2000cwt.googlegro ups.com...

大家好,


我有一个主表格(比如form1) ).i想要显示另一个表格(比如

" form2")发生一个事件(比如按一下按钮)并想要隐藏

一段时间后因此,它会在发生同一事件时再次显示。我通过创建form2的对象来开发它。

通过调用form2.Show在事件中显示它()并通过调用

form2.Hide()隐藏它。


问题是在显示form2时我的内存使用情况

应用程序增加了很多。在

隐藏form2期间不会减少。然后应用程序在事件发生期间每隔一次就会占用内存。


当我尝试form2.WindowState = FormWindowState.Minimized时而不是隐藏它的
,内存使用量会减少。但我的目的是隐藏表单

以便每次事件发生时都会显示

请提出解决此问题的方法。


问候,

Alex
Hello all,

I have a main form(say "form1") .i want to display another form(say
"form2") on occuring of an event (say a button click) and want to hide
it after some time so that it will again displays while occuring of the
same event.I develop it by creating an object of the form2 and
displays it in the event by calling form2.Show() and hide it by calling
form2.Hide().

the problem is that while displaying the form2 the memory usage of my
application increases by a huge amount.it wont decrease during the
hiding of the form2. Then the application eats memory every
times,during the occurnce of the event.

when i tried "form2.WindowState = FormWindowState.Minimized" instead of
hiding it, the memory usage decreases .But my aim is to hide the form
so that it will displays every time the event occurs
please suggest any method for solving this problem.

regards,
Alex



感谢您的即时回复,


实际上,如果我关闭表单而不是隐藏它,当事件发生时b / b
下次我想再次创建对象(即Form2 form2 =

new Form2),所以我更喜欢将form2隐藏起来而不是关闭

它。


我还尝试了一个简单的应用程序,在每个

按钮上显示一个简单的表单,但它也显示了同样的问题。

任何想法解决这个问题?


问候,

Alex


Dave Sexton写道:
Thanks for your immediate reply,

Actually if i close the form instead of Hiding it, when the event
occurs on the next time i want to create the object( ie Form2 form2 =
new Form2 ) again, so i prefered the form2 to Hide instead of closing
it.

I also tried a simple application that displays a simple form on every
button click but It also shows the same problem.
Any idea for solving this?

regards,
Alex

Dave Sexton wrote:

你好Alex,


你能关闭form2然后再显示ea需要时间吗?


关闭表单将处理其非托管资源,希望释放一些内存。如果它不是那么你可能会遇到更大的问题。


确保你使用的任何非托管组件都在

Dispose方法中释放表格也是如此。


-

Dave Sexton
http://davesexton.com/blog

" Alex" < al ****** @ gmail.comwrote in message

news:11 ********************** @ 42g2000cwt .googlegro ups.com ...
Hi Alex,

Can you Close form2 and then Show it again each time it''s required?

Closing the Form will Dispose of its unmanaged resources, hopefully freeing
up some memory. If it doesn''t then you may have a bigger problem.

Make sure that any unmanaged components that you are using are freed in the
Dispose method of the Form as well.

--
Dave Sexton
http://davesexton.com/blog

"Alex" <al******@gmail.comwrote in message
news:11**********************@42g2000cwt.googlegro ups.com...

大家好,


我有一个主表格(比如form1) ).i想要显示另一个表格(比如

" form2")发生一个事件(比如按一下按钮)并想要隐藏

一段时间后因此,它会在发生同一事件时再次显示。我通过创建form2的对象来开发它。

通过调用form2.Show在事件中显示它()并通过调用

form2.Hide()隐藏它。


问题是在显示form2时我的内存使用情况

应用程序增加了很多。在

隐藏form2期间不会减少。然后应用程序在事件发生期间每隔一次就会占用内存。


当我尝试form2.WindowState = FormWindowState.Minimized时而不是隐藏它的
,内存使用量会减少。但我的目的是隐藏表单

以便每次事件发生时都会显示

请建议任何解决此问题的方法。


问候,

Alex
Hello all,

I have a main form(say "form1") .i want to display another form(say
"form2") on occuring of an event (say a button click) and want to hide
it after some time so that it will again displays while occuring of the
same event.I develop it by creating an object of the form2 and
displays it in the event by calling form2.Show() and hide it by calling
form2.Hide().

the problem is that while displaying the form2 the memory usage of my
application increases by a huge amount.it wont decrease during the
hiding of the form2. Then the application eats memory every
times,during the occurnce of the event.

when i tried "form2.WindowState = FormWindowState.Minimized" instead of
hiding it, the memory usage decreases .But my aim is to hide the form
so that it will displays every time the event occurs
please suggest any method for solving this problem.

regards,
Alex




" Alex" < al ****** @ gmail.comwrote in message

news:11 ********************** @ 42g2000cwt .googlegro ups.com ...
Hi,
"Alex" <al******@gmail.comwrote in message
news:11**********************@42g2000cwt.googlegro ups.com...

大家好,


我有一个主表格(比如form1) ).i想要显示另一个表格(比如

" form2")发生一个事件(比如按一下按钮)并想要隐藏

一段时间后因此,它会在发生同一事件时再次显示。我通过创建form2的对象来开发它。

通过调用form2.Show在事件中显示它()并通过调用

form2.Hide()隐藏它。


问题是在显示form2时我的内存使用情况

申请量增加了很多。
Hello all,

I have a main form(say "form1") .i want to display another form(say
"form2") on occuring of an event (say a button click) and want to hide
it after some time so that it will again displays while occuring of the
same event.I develop it by creating an object of the form2 and
displays it in the event by calling form2.Show() and hide it by calling
form2.Hide().

the problem is that while displaying the form2 the memory usage of my
application increases by a huge amount.



我们谈的有多大?

How big we are talking about?


当我试过form2.WindowState = FormWindowState。最小化"而不是

隐藏它,内存使用量减少
when i tried "form2.WindowState = FormWindowState.Minimized" instead of
hiding it, the memory usage decreases



你可以试试minimaze&后来隐藏了吗?

-

Ignacio Machin

machin AT laceupsolutions com

Can you try minimaze & later hide it?
--
Ignacio Machin
machin AT laceupsolutions com


这篇关于隐藏表单时内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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