本文介绍了是否每个用户定义的类需要实现IDisposable接口获取垃圾回收的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道怎么的用户定义的类对象的垃圾收集。我需要实现每类IDisposable接口,并调用Dispose()方法以释放内存?

I am not sure how the user defined class objects are garbage collected. Do I need to implement IDisposable interface on every class and call the dispose() method on it to free the memory?

推荐答案

没有。每一个正常的管理的.NET对象获得当你停止指的是垃圾回收。 IDisposable接口意味着你你将实施一个需要被调用者称为Dispose()方法 - 它通常释放未garbaged收集的东西。它也有助于与具有确定性的地方,释放内存

No. Every normal managed .NET object gets garbage collected when you stop referring to it. IDisposable means that you you will implement a Dispose() method that needs to be called by the caller -- it usually releases things that aren't garbaged collected. It also helps with having a deterministic place to release memory.

退房的IDisposable模式,以确保你这样做是正确的:

Check out the IDisposable pattern to make sure you do it right:

这篇关于是否每个用户定义的类需要实现IDisposable接口获取垃圾回收的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-18 20:21