In object-oriented programming languages that use garbage collection, a finalizer is a special method that is executed when an object is garbage collected. It is similar in function to a destructor. In less technical terms, a finalizer is a piece of code that ensures that certain necessary actions are taken when an acquired resource (such as a file or access to a hardware device) is no longer being used.
| Property | Value |
| dbpedia-owl:abstract
|
- In object-oriented programming languages that use garbage collection, a finalizer is a special method that is executed when an object is garbage collected. It is similar in function to a destructor. In less technical terms, a finalizer is a piece of code that ensures that certain necessary actions are taken when an acquired resource (such as a file or access to a hardware device) is no longer being used. This could be closing the file or signalling to the operating system that the hardware device is no longer needed. However, as noted below, finalizers are not the preferred way to accomplish this and for the most part serve as a fail-safe. Unlike destructors, finalizers are usually not deterministic. A destructor is run when the program explicitly frees an object. In contrast, a finalizer is executed when the internal garbage collection system frees the object. Depending on the garbage collection method used, this may happen at an arbitrary moment after the object is freed, possibly never. Programming languages which use finalizers include C# and Java. In C#, and a few others which support finalizers, the syntax for declaring a finalizer mimics that of destructors in C++. Due to the lack of programmer control over their execution, it is usually recommended to avoid finalizers for any but the most trivial operations. In particular, operations often performed in destructors are not usually appropriate for finalizers. For example, destructors are often used to free expensive resources such as file or network handles. If placed in a finalizer, the resources may remain in use for long periods of time after the program is finished with them. Instead, most languages encourage the dispose pattern whereby the object has a method to clean up the object's resources, leaving the finalizer as a fail-safe in the case where the dispose method doesn't get called. (The C# language supports the dispose pattern explicitly, via the interface and the keyword. ) Languages with finalizers must also address the problem of object resurrection. Resurrection occurs when an object's finalizer causes the object to become reachable (that is, not garbage). The garbage collector must determine if the object has been resurrected by the finalizer, or risk creating a dangling reference. Languages have adopted several different solutions. For example, Java will not free the object until it has proven that the object is once again unreachable, but will not run the finalizer more than once http://download. oracle. com/javase/6/docs/api/java/lang/Object. html#finalize. Objective-C 2.0 will put resurrected objects into a "zombie" state where they log all messages sent to them, but do nothing else http://developer. apple. com/library/mac/documentation/Cocoa/Conceptual/GarbageCollection/Articles/gcFinalize. html#//apple_ref/doc/uid/TP40002453-SW2.
- Финализа́тор в объектно-ориентированных языках программирования, использующих механизм сборки мусора, — специальный метод, вызываемый средой исполнения перед удалением объекта сборщиком мусора.
|
| dbpedia-owl:wikiPageExternalLink
| |
| dcterms:subject
| |
| rdfs:comment
|
- Финализа́тор в объектно-ориентированных языках программирования, использующих механизм сборки мусора, — специальный метод, вызываемый средой исполнения перед удалением объекта сборщиком мусора.
- In object-oriented programming languages that use garbage collection, a finalizer is a special method that is executed when an object is garbage collected. It is similar in function to a destructor. In less technical terms, a finalizer is a piece of code that ensures that certain necessary actions are taken when an acquired resource (such as a file or access to a hardware device) is no longer being used.
|
| rdfs:label
| |
| owl:sameAs
| |
| foaf:page
| |
| is dbpedia-owl:wikiPageRedirects
of | |
| is owl:sameAs
of | |
| is foaf:primaryTopic
of | |