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# 重點并不是在這里
添加回答
舉報
0/150
提交
取消