Must see — Finalize(), dispose(), close()

The Finalize() method is similar to the traditional destructor in C++. Unfortunately, Finalize() is not deterministic.
If a lot of objects need to run Finalize(), there will be a high load on the garbage collector, which in turn results in a major degradation in application performance with no measurable positive impact on the garbage collection process.

It is better to use a declared destructor rather than Finalize(). Declaring a destructor (~classname) is more in line with the C++ culture, but it still only calls the Finalize(), so the issue of deterministic destruction is still there.

The C# compiler will actually convert the declared destructor to a call to the Finalize() method. The Finalize() method is called recursively for all of the instances in the inheritance chain, from the most derived to the least derived.
it is better to use the Close() and Dispose() methods.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s