如何完全删除引用的对象? [英] How to delete the referenced object Completely?

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

问题描述


这是我的代码:

Hi,
Here is my code:

class A
{
  Class B
  {
  }
}

Class C
{
  //stores the references of Class B
}


我正在词典中收集A的对象.当我从字典中删除A的对象之一时,相应的B的对象也应删除.但是B的参考没有被删除.


I am collecting the objects of A in a Dictionary. When I delete one of the object of A from dictionary then the corresponding B''s object should also get deleted. But B''s reference is not getting deleted.

Will you please tell how to accomplish this?

推荐答案

通过在继承列表中添加"IDisposable"接口,使A类成为一次性对象,并在Dispose中手动终止引用方法.
Make class A disposable by adding the "IDisposable" interface to the inheritance list, and manually kill the reference in the Dispose method.


这篇关于如何完全删除引用的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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