处置对象? [英] Disposing Objects?

查看:105
本文介绍了处置对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在开发一个财务应用程序,你知道在这些类似的应用程序中有大量的数据量。我有一个MDIChild表单,

其他表单以这种形式打开。例如,在一个表单中,我从数据库中获取许多

行,以便在客户端计算机上向用户显示它们。

之后,这个进程内存会变高,但当用户关闭该表单时,

内存保持不变。


我正在使用我的实体的IDisposable接口,我在我们的实体处理时使用GC.Collect()和

GC.SuppressFinalize()方法。

但我无法实现减少内存量。如何在用户关闭表单后减少内存量?
用户在C#中关闭表单后,有没有办法立即得到

?谢谢...

解决方案

你如何测量内存占用量?


Mike Ober。


" Adam Right" < ad ** @ right.comwrote in message

news:Ot ************** @ TK2MSFTNGP03.phx.gbl ...
< blockquote class =post_quotes>



我正在开发一个财务应用程序,你知道有大量

的数据量这些类似的应用。我有一个MDIChild表格和

其他表格以这种形式打开。例如,在一个表单中,我从数据库中取出许多行,以便在客户端上向用户显示它们的b $ b机器。在此过程后内存变得更高但是当用户关闭时,形成内存的
保持相同的数量。


我正在为我的实体使用IDisposable接口而我使用GC.Collect()

和GC.SuppressFinalize()方法为我的实体处理

。但我无法实现减少内存量。

如何减少用户关闭表单后的内存量?用户在C#中关闭表单后,是否有立即获得该结果的方法?

谢谢......



嗨Mike,


我不明白你的内存占用是什么意思?如果你问我在哪里寻找当前的内存大小,我会使用任务管理器。你能详细解释一下b $ b吗?谢谢...


Michael D. Ober < obermd。@。alum.mit.edu.nospamwrote in message

news:%2 **************** @ TK2MSFTNGP03.phx.gbl。 ..


你如何测量内存占用量?


Mike Ober。


Adam Right < ad ** @ right.comwrote in message

news:Ot ************** @ TK2MSFTNGP03.phx.gbl ...
< blockquote class =post_quotes>
>

我正在开发一个财务应用程序,你知道在这些类似的应用程序中有大量的数据。我有一个MDIChild表单,
其他表单以这种形式打开。例如,在一个表单中,我从数据库中获取许多行,以便在客户端
机器上向用户显示它们。在这个过程后内存变得更高但是当用户关闭时,形成的内存仍然是相同的数量。

我正在为我的实体使用IDisposable接口,我使用GC.Collect()
和我的实体处理时的GC.SuppressFinalize()方法。但我无法实现减少内存量。如何在用户关闭表单后减少内存量?有没有办法在用户关闭C#中的表单后立即获得该结果?谢谢...







10月17日上午10点13分,Adam Right < a ... @ right.comwrote:





我正在开发一个财务应用程序,你知道在这些类似的应用程序中有大量的数据量。我有一个MDIChild表单,

其他表单以这种形式打开。例如,在一个表单中,我从数据库中获取许多

行,以便在客户端计算机上向用户显示它们。

之后,这个进程内存会变高,但当用户关闭该表单时,

内存保持不变。


我正在使用我的实体的IDisposable接口,我在我们的实体处理时使用GC.Collect()和

GC.SuppressFinalize()方法。

但我无法实现减少内存量。如何在用户关闭表单后减少内存量?
用户在C#中关闭表单后,有没有办法立即得到

?谢谢...



亚当,


可以使用。仅对直接或间接的类使用IDisposable

持有非托管资源。如果您的对象只是从数据库中获取有关

实体的信息,那么我敢打赌他们根本不会持有非托管的资金。其次,你应该只重写终结器

(析构函数)并在类直接

持有非托管资源时调用GC.SuppressFinalize。第三,很少需要GC.Collect。

运行时确定GC何时需要运行。

手动调用GC.Collect通常会导致性能下降

申请。


你确定这些物品不再被引用吗?


Brian


Hi,

I am developing a financial application and you know that there are huge
amount of data in these similar aplications. I have a MDIChild form and the
other forms are opened in this form. For example, in a form i fetch many
rows from the database to show them to the user on the client machine. After
this process memory gets higher but when the user closes that form the
memory remains same amount.

I am using IDisposable interface for my entities and i use GC.Collect() and
GC.SuppressFinalize() method for my entities while they are being disposed.
But i cannot achieve to reduce the amount of the memory. How can i reduce
the amount of memory after the user closes the form? Is there a way to get
that result immediate after the user closes the form in C#? Thanks...

解决方案

How are you measuring the memory footprint?

Mike Ober.

"Adam Right" <ad**@right.comwrote in message
news:Ot**************@TK2MSFTNGP03.phx.gbl...

Hi,

I am developing a financial application and you know that there are huge
amount of data in these similar aplications. I have a MDIChild form and
the other forms are opened in this form. For example, in a form i fetch
many rows from the database to show them to the user on the client
machine. After this process memory gets higher but when the user closes
that form the memory remains same amount.

I am using IDisposable interface for my entities and i use GC.Collect()
and GC.SuppressFinalize() method for my entities while they are being
disposed. But i cannot achieve to reduce the amount of the memory. How can
i reduce the amount of memory after the user closes the form? Is there a
way to get that result immediate after the user closes the form in C#?
Thanks...



Hi Mike,

I do not understand what do you mean with Memory footprint? If you ask where
am i looking for the current memory size, i use task manager. Can you
explain in details? Thanks...

"Michael D. Ober" <obermd.@.alum.mit.edu.nospamwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...

How are you measuring the memory footprint?

Mike Ober.

"Adam Right" <ad**@right.comwrote in message
news:Ot**************@TK2MSFTNGP03.phx.gbl...

>Hi,

I am developing a financial application and you know that there are huge
amount of data in these similar aplications. I have a MDIChild form and
the other forms are opened in this form. For example, in a form i fetch
many rows from the database to show them to the user on the client
machine. After this process memory gets higher but when the user closes
that form the memory remains same amount.

I am using IDisposable interface for my entities and i use GC.Collect()
and GC.SuppressFinalize() method for my entities while they are being
disposed. But i cannot achieve to reduce the amount of the memory. How
can i reduce the amount of memory after the user closes the form? Is
there a way to get that result immediate after the user closes the form
in C#? Thanks...






On Oct 17, 10:13 am, "Adam Right" <a...@right.comwrote:

Hi,

I am developing a financial application and you know that there are huge
amount of data in these similar aplications. I have a MDIChild form and the
other forms are opened in this form. For example, in a form i fetch many
rows from the database to show them to the user on the client machine. After
this process memory gets higher but when the user closes that form the
memory remains same amount.

I am using IDisposable interface for my entities and i use GC.Collect() and
GC.SuppressFinalize() method for my entities while they are being disposed.
But i cannot achieve to reduce the amount of the memory. How can i reduce
the amount of memory after the user closes the form? Is there a way to get
that result immediate after the user closes the form in C#? Thanks...

Adam,

First, I just want to clarify the situations where IDisposable should
be used. Use IDisposable only for class that directly or indirectly
hold unmanaged resources. If your objects just hold information about
entities from the database then I''d bet they don''t hold unmanaged
resources at all. Second, you should only be overriding the finalizer
(destructor) and calling GC.SuppressFinalize when the class directly
holds unmanaged resources. Third, GC.Collect is rarely needed. The
runtime does a pretty good job determining when the GC needs to run.
Manual calls to GC.Collect often lead to poorer performing
applications.

Are you certain these objects are no longer referenced anywhere?

Brian


这篇关于处置对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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