How to destroy an object in C#
This question already has an answer here:
除了将对象设置为null之外,还应该将其从其他对象中移除,如果您使用的资源需要释放,请使用IDisposable
public class Car: IDisposable
{
// free resources
public void Dispose()
{
}
}
set c = null;
As long as there are no other references to it, the garbage collector will destroy it the next time it runs.
下一篇: 如何在C#中销毁对象