翻訳と辞書 |
Finalization : ウィキペディア英語版 | Finalization
In object-oriented programming, finalization is the process of preparing an object for deallocation; strictly speaking, finalization is all parts of object destruction until memory deallocation itself. Finalization is formally complementary to initialization, which is the part of object creation that follows allocation, but differs significantly in practice – see contrast with initialization. Finalization fulfills a similar role as finally in exception handling; in general these are unrelated, but in some cases the behavior is identical, and the case of finally in a coroutine can be considered a form of finalization – see connection with finally. The term "final" is also used to indicate a class that cannot be inherited; this is unrelated. Finalization varies significantly between languages and between implementations of a language, depending on memory management method, and can generally be partially controlled per-object or per-class by a user-specified finalizer or destructor, unlike deallocation. The terms "finalization" and "finalizer" are primarily used in languages with garbage collection, especially with non-deterministic object lifetimes, like Java; while "destruction" and "destructor" are used for languages with deterministic object lifetimes, like C++. This article addresses finalization in the broad sense, regardless of object lifetime or memory management method, but distinguishes how finalization differs depending on these. ==Use== Finalization is primarily used for cleanup, to release memory or other resources: to deallocate memory allocated via manual memory management; to clear references if reference counting is used (decrement reference counts); to release resources, particularly in the Resource Acquisition Is Initialization (RAII) idiom; or to unregister an object. The amount of finalization varies significantly between languages, from extensive finalization in C++, which has manual memory management, reference counting, and deterministic object lifetimes; to often no finalization in Java, which has non-deterministic object lifetimes and is often implemented with a tracing garbage collector. It is also possible for there to be little or no explicit (user-specified) finalization, but significant implicit finalization, performed by the compiler, interpreter, or runtime; this is common in case of automatic reference counting, as in the CPython reference implementation of Python, or in Automatic Reference Counting in Apple's implementation of Objective-C, which both automatically break references during finalization. Memory deallocation during finalization is common in languages like C++ where manual memory management is standard, but also occurs in managed languages when memory has been allocated outside of the managed heap (externally to the language); in Java this occurs with Java Native Interface (JNI) and ByteBuffer objects in New I/O (NIO). This latter can cause problems due to the garbage collector not being able to track these external resources, so they will not be collected aggressively enough, and can cause out-of-memory errors due to exhausting unmanaged memory – this can be avoided by treating native memory as a resource and using the dispose pattern, as discussed below.
抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)』 ■ウィキペディアで「Finalization」の詳細全文を読む
スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース |
Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.
|
|