为了账号安全,请及时绑定邮箱和手机立即绑定

MarshalByValueComponent类的Dispose功能是什么?

MarshalByValueComponent类的Dispose功能是什么?

斯蒂芬大帝 2022-05-26 15:11:26
MarshalByValueComponent类是如何实现IDisposable..::.Dispose(),MarshalByValueComponent类的Dispose功能是什么,有详细代码吗??备注:使用完 MarshalByValueComponent 后调用 Dispose。Dispose 方法使 MarshalByValueComponent 处于不可用状态。调用完 Dispose 后,必须释放对 MarshalByValueComponent 的所有引用,这样垃圾回收器才能收回 MarshalByValueComponent 占用的内存千万别简单说是“释放资源”!
查看完整描述

1 回答

?
绝地无双

TA贡献1946条经验 获得超4个赞

确实是释放资源啊。

你要看的话= = 那看吧

public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
//然后gc 回收垃圾 gc 回收垃圾 要讲就讲的多了 自己去查文章吧
}

///this.Dispose(true); 调用这里
protected virtual void Dispose(bool disposing)
{
if (disposing)
{
lock (this)
{
if ((this.site != null) && (this.site.Container != null))
{
this.site.Container.Remove(this);
}
if (this.events != null)
{
EventHandler handler = (EventHandler) this.events[EventDisposed];
if (handler != null)
{
handler(this, EventArgs.Empty);
}
}
}
}
}

其实 .net 这玩意儿 就是让你在不了解
某些东西的情况下 任然能写出质量比较高的代码, 比如内存控制
当然 了解才能更好的使用它。 所以这些东西 大概知道就行了,毕竟c# 重点并不是在这里



查看完整回答
反对 回复 2022-05-30
  • 1 回答
  • 0 关注
  • 128 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信