Methods Destrutores
are used to release memory dynamically allocated by the class, to delete references to it, when it does not exist.
In Programming Languages you have the Garbage Collector
, the use of destructive methods is not necessary, since the Garbage Collector
takes care of doing this.
The need to create them is in cases where language does not have the Garbage Collector
, and it is necessary to destroy the class after its use, so that it does not occupy mémoria.
In languages that have the Garbage Collector
, use is only necessary when using unmanaged resources.
The most common types of unmanaged resources are objects involving operating system resources such as files, windows, network connections, or database connections. Microsoft
In such cases the Garbage Collector
does not know how to release and clear unmanaged resource.
Not all languages make use of the signal ~
to designate a destructor.
In PHP
for example is used __
:
void __destruct ( void )
Python
def __del__(self):
Related or duplicated: http://answall.com/q/9078/101
– Maniero
@I think the answer that was chosen does not answer my question. The other one even responds, but it might be a good idea to wait for other answers. Don’t you think?
– Jéf Bueno
Related: What good is a builder?
– Math
@Jéfersonbueno and my answer? There it is duplicated.
– Maniero
It is for people who have reached your question to see that there is a related (or complementary) subject and can already amend the reading of the other topic. In addition, it is "featured" in the links below "Linked". Making this link easier.
– Math
@bigown in general, answer. Although she is specific to C#, you can have a notion. If you want I can mark it as duplicate.
– Jéf Bueno
@Math understood. Thank you.
– Jéf Bueno