垃圾收集在.NET [英] Garbage Collectionin .NET

查看:66
本文介绍了垃圾收集在.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


我明白.net框架有垃圾收集器自动运行

并释放内存。


但是在我的C#应用​​程序中,我有一个永远不会发布的对象。


我可以在.NET中实现吗?


紧急回应是neede,因为我对我的开发工作很感兴趣

这里。


非常感谢为你的时间。


问候。

Hi All

I understand that the .net framework has garbagecollectors which run
automatically and release memory.

But in my application in C#, i have an object which should never be
released.

Can I achieve this in .NET ?

An urgent response is neede, as I am struck up with my development work
here.

Thanks a lot for your time.

Regards.

推荐答案

Rimonne,
Rimonne,
但是在我的C#应用​​程序中,我有一个永远不会发布的对象。

我可以在.NET中实现这个吗?
But in my application in C#, i have an object which should never be
released.

Can I achieve this in .NET ?




您所要做的就是确保您的应用程序引用了

对象。因此,它永远不会被释放。


问候,


兰迪



All you have to do is make sure your application has a reference to the
object. Therefore, it will never be released.

Regards,

Randy


我可以使用

GC.SuppressFinalize方法吗?只需在msdn中阅读它。


" Randy A. Ynchausti" < RA ************* @ msn.com>在消息中写道

news:Ob ************** @ TK2MSFTNGP11.phx.gbl ...
Cant i use
GC.SuppressFinalize method for this? Just read it in msdn.

"Randy A. Ynchausti" <ra*************@msn.com> wrote in message
news:Ob**************@TK2MSFTNGP11.phx.gbl...
Rimonne,
Rimonne,
但是在我的C#应用​​程序中,我有一个永远不会发布的对象。

我可以在.NET中实现这个吗?
But in my application in C#, i have an object which should never be
released.

Can I achieve this in .NET ?



您所要做的就是确保您的应用程序引用了
对象。因此,它永远不会被释放。

问候,

兰迪



All you have to do is make sure your application has a reference to the
object. Therefore, it will never be released.

Regards,

Randy



我不能使用
GC.SuppressFinalize方法吗?只需在msdn中阅读。
Cant i use
GC.SuppressFinalize method for this? Just read it in msdn.




否,GC.SuppressFInalize只是防止Finalize方法被调用(对性能有好处)收集对象。


正如兰迪所说,保持对物体的实时参考。


Mattias


-

Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com

请回复到新闻组。



No, GC.SuppressFInalize just prevents the Finalize method from being
called (good for performance) once the object is collected.

As Randy said, keep a live reference to the object.

Mattias

--
Mattias Sj?gren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


这篇关于垃圾收集在.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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