Instance Method インスタンスメソッド

finalize()

The garbage collector invokes this method on the receiver before disposing of the memory it uses. ガベージコレクションは、このメソッドをレシバー上で、それが使うメモリの処分を行う前に発動します。

Declaration 宣言

func finalize()

Discussion 解説

The garbage collector invokes this method on the receiver before disposing of the memory it uses. ガベージコレクションは、このメソッドをレシバー上で、それが使うメモリの処分を行う前に発動します。 When garbage collection is enabled, this method is invoked instead of dealloc.

You can override this method to relinquish resources the receiver has obtained, as shown in the following example: あなたはこのメソッドをオーバーライドして、レシーバが獲得しているリソースを放棄することができます、以下の例で示すように:


- (void)finalize {
    if (log_file != NULL) {
        fclose(log_file);
        log_file = NULL;
    }
    [super finalize];
}

Typically, however, you are encouraged to relinquish resources prior to finalization if at all possible. 通常は、しかしながら、あなたはともかく可能ならばファイナライゼーションの前にリソースを放棄するのを奨励されます。 For more details, see Implementing a finalize Method.

Special Considerations 特別な注意事項

It is an error to store self into a new or existing live object (colloquially known as “resurrection”), which implies that this method will be called only once. However, the receiver may be messaged after finalization by other objects also being finalized at this time, so your override should guard against future use of resources that have been reclaimed, as shown by the log_file = NULL statement in the example. The finalize method itself will never be invoked more than once for a given object.

See Also 参照

Deprecated Methods 非推奨メソッド

Related Documentation 関連文書