Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Object lifetime
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Destruction=== {{anchor|Object destruction}} Generally, an object is removed from memory after it is no longer needed. However, if there is sufficient memory or a program has a short run time, object destruction may not occur; memory simply being deallocated at process termination. In some cases, object destruction consists solely of deallocating memory, particularly with garbage-collection, or if the object is a [[plain old data structure]]. In other cases, cleanup is performed prior to deallocation, particularly destroying member objects (in manual memory management), or deleting references from the object to other objects to decrement reference counts (in reference counting). This may be automatic, or a special destruction method may be called on the object. In class-based languages with deterministic object lifetime, notably C++, a ''[[destructor (computer science)|destructor]]'' is called when an instance is deleted, before the memory is deallocated. In C++, destructors differ from constructors in various ways. They cannot be overloaded, must have no arguments, need not maintain [[class invariant]]s, and can cause program termination if they throw exceptions. With [[garbage collection (computer science)|garbage collection]], objects may be destroyed when they can no longer be accessed by the program. The garbage-collector calls a ''[[finalizer]]'' before memory deallocation. Destroying an object will cause any references to the object to become invalid. With manual memory management, any existing reference becomes a [[dangling reference]]. With garbage collection, objects are only destroyed when there are no references to them.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)