Destructor (computer programming)

In object-oriented programming, a destructor (sometimes abbreviated dtor) is a method which is invoked mechanically just before the memory of the object is released. It can happen when its lifetime is bound to scope and the execution leaves the scope, when it is embedded in another object whose lifetime ends, or when it was allocated dynamically and is released explicitly. Its main purpose is to free the resources (memory allocations, open files or sockets, database connections, resource locks, etc.) which were acquired by the object during its life and/or deregister from other entities which may keep references to it. Use of destructors is needed for the process of Resource Acquisition Is Initialization (RAII).

Comment
enIn object-oriented programming, a destructor (sometimes abbreviated dtor) is a method which is invoked mechanically just before the memory of the object is released. It can happen when its lifetime is bound to scope and the execution leaves the scope, when it is embedded in another object whose lifetime ends, or when it was allocated dynamically and is released explicitly. Its main purpose is to free the resources (memory allocations, open files or sockets, database connections, resource locks, etc.) which were acquired by the object during its life and/or deregister from other entities which may keep references to it. Use of destructors is needed for the process of Resource Acquisition Is Initialization (RAII).
Has abstract
enIn object-oriented programming, a destructor (sometimes abbreviated dtor) is a method which is invoked mechanically just before the memory of the object is released. It can happen when its lifetime is bound to scope and the execution leaves the scope, when it is embedded in another object whose lifetime ends, or when it was allocated dynamically and is released explicitly. Its main purpose is to free the resources (memory allocations, open files or sockets, database connections, resource locks, etc.) which were acquired by the object during its life and/or deregister from other entities which may keep references to it. Use of destructors is needed for the process of Resource Acquisition Is Initialization (RAII). With most kinds of automatic garbage collection algorithms, the releasing of memory may happen a long time after the object becomes unreachable, making destructors (called finalizers in this case) unsuitable for most purposes. In such languages, the freeing of resources is done either through a lexical construct (such as try..finally, Python's "with" or Java's "try-with-resources"), which is the equivalent to RAII, or explicitly by calling a function (equivalent to explicit deletion); in particular, many object-oriented languages use the Dispose pattern.
Hypernym
Method
Is primary topic of
Destructor (computer programming)
Label
enDestructor (computer programming)
Link from a Wikipage to another Wikipage
Automatic variable
C (programming language)
C++
Category:C++
Category:Method (computer programming)
Code refactoring
Constructor (computer science)
D (programming language)
Database connection
Dispose pattern
Finalizer
Garbage collection (computer science)
GNU Compiler Collection
Memory management
Method (computer science)
Moose (Perl)
Object (computer science)
Objective-C
Object lifetime
Object-oriented programming
Object Pascal
Perl
PHP
Python (programming language)
Resource (computer science)
Resource Acquisition Is Initialization
Rust (programming language)
Scalar type
Scope (computer science)
Scott Meyers
Smart pointer
Swift (programming language)
Tilde
Virtual function
Xojo
SameAs
4uGde
Destructeur
Destructor (computer programming)
Destructor (informatica)
Destructor (informática)
Destruktor
Destruktor
Destruktor
Destruktor
Destruktor
Destruktori
Destruktorius (programavimas)
Destrutor (programação)
Distruttore (informatica)
Hàm hủy (lập trình máy tính)
m.06zfg1
Q735151
Деструктор
Деструктор (програмування)
مخرب (برنامه‌نویسی رایانه)
デストラクタ
解構子
소멸자 (컴퓨터 프로그래밍)
Subject
Category:C++
Category:Method (computer programming)
WasDerivedFrom
Destructor (computer programming)?oldid=1123795019&ns=0
WikiPageLength
9226
Wikipage page ID
2253076
Wikipage revision ID
1123795019
WikiPageUsesTemplate
Template:Cpp
Template:Reflist
Template:Visible anchor