我如何在C#中释放对象 [英] How do i free objects in C#

查看:988
本文介绍了我如何在C#中释放对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以告诉我如何在C#中释放对象吗? 例如,我有一个对象:

Can anyone please tell me how I can free objects in C#? For example, I have an object:

Object obj1 = new Object();
//Some code using obj1
/*
Here I would like to free obj1, 
after it is no longer required 
and also more importantly 
its scope is the full run time of the program.
*/

感谢您的所有帮助

推荐答案

您不必这样做.运行时的垃圾收集器将随之出现,并为您清理它.这就是为什么首先使用C#而不是非托管C ++的原因:)

You don't have to. The runtime's garbage collector will come along and clean it up for you. That is why you are using C# and not unmanaged C++ in the first place :)

这篇关于我如何在C#中释放对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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