Finalizers
Resources of an object are cleaned up in a Finalize method. Before an object is removed from memory, the Finalize method is called to allow for cleanup that is related to the object. Finalize methods are called finalizers. Every object inherits the Finalize method from the System.Object type. Here is the signature of the Finalize method:
protected virtual void Finalize()
Finalizers are not called programmatically; they are called automatically during the garbage collection cycle. Garbage collection is nondeterministic, which means that the finalizer may not be called immediately after the object no longer is needed. Unmanaged resources that might be released in a finalizer, such as files, database connections, and devices, might not be ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access