Finalize
is protected and, therefore, is accessible only through this class or a derived class.
This method is automatically called after an object becomes inaccessible, unless the object has been exempted from finalization by a call to SuppressFinalize.During shutdown of an application domain, Finalize is automatically called on objects that are not exempt from finalization, even those that are still accessible.
Finalize
is automatically called only once on a given instance, unless the object is re-registered using a mechanism such as ReRegisterForFinalize and GC.SuppressFinalize has not been subsequently called.
Every implementation of Finalize in a derived type must call its base type's implementation of Finalize.This is the only case in which application code is allowed to call Finalize.
Finalize
operations have the following limitations:
The tempo EXACT when the finalizador executes During Garbage coleção is indefinido.Resources are not guaranteed to be released at any specific time, unless calling a Close method or a Dispose method.
Os finalizadores dos dois objetos não são garantidas para ser executado em qualquer ordem específica, mesmo se um objeto se refere a outro.Isto é, se um objeto tem uma referência a objeto B e ambos tiverem finalizadores, Objeto B pode ter já finalizado quando inicia o finalizador de um objeto.
O thread no qual o finalizador é executado não for especificado.
The Finalize method might not run to completion or might not run at all in the following exceptional circumstances:
Indefinitely bBloquears finalizador another (goes into an INFINITE executar um loop, tries to obtain a Bloquear it can never Obtain and SO on).Porque o tempo de execução tenta executar finalizadores até a conclusão, outros finalizadores podem não ser chamados se um blocos finalizador indefinidamente.
The processo terminates without a chance to the tempo de execução giving Apagar UP.Neste do maiúsculas e minúsculas, a tempo de execução Primeiro notificação de terminação processo é uma notificação DLL_PROCESS_DETACH.
The runtime continues to Finalize objects during shutdown only while the number of finalizable objects continues to decrease.
If Finalize or an override of Finalize throws an exception, and the runtime is not hosted by an application that overrides the default policy, the runtime terminates the process and no active try-finally blocks or finalizers are executed.This Comportamento ensures If the Cannot livre or Destroy Resources.
OBSERVAÇÕES PARA Implementers:
Object.Finalize
does nothing by default.It must be overridden by a derived class only if necessary, because reclamation during garbage collection tends to take much longer if a Finalize operation must be run.
If an Object holds references to any resources, Finalize must be overridden by a derived class in order to free these resources before the Object is discarded during garbage collection.
A type must implement Finalize when it uses unmanaged resources such as file handles or database connections that must be released when the managed object that uses them is reclaimed.See the IDisposable interface for a complementary and more controllable means of disposing resources.
Finalize
can take any action, including resurrecting an object (that is, making the object accessible again) after it has been cleaned up during garbage collection.However, the object can only be resurrected once; Finalize cannot be called on resurrected objects during garbage collection.
c#Destruidores são o mecanismo C# para executar operações de limpeza.Destruidores fornecem proteções apropriadas, como chamar automaticamente destruidor do tipo base.In C# code, Object.Finalize cannot be called or overridden.