Loading...
「ツール」は右上に移動しました。
利用したサーバー: wtserver1
69いいね 5,717 views回再生

dispose vs finalize in c#

Garbage collector (GC) plays the main and important role in .NET for memory management so programmer can focus on the application functionality.

GC calls destructor who cleans up managed resources

The programmer has no control over when the destructor is called because this is determined by the garbage collector


What is difference between Finalize and Dispose method in terms of memory management?
Ans. Finalize and Dispose both are used for clearing Unmanaged resources.
Finalize is bit expensive because it is called by GC(garbage collector). GC maintains a separate queue/array when it adds all object which has finalized implemented.

It is always recommended that, one should not implement the Finalize method until it is extremely necessary. First priority should always be to implement the Dispose method and clean unmanaged as soon as possible when processing finish with that.

Can we call GC explicitely?
Ans. Yes.

コメント