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
Smart pointer
(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!
{{short description|Data type simulating a pointer with additional features}} {{more citations needed|date=June 2015}} {{use dmy dates|date=July 2022|cs1-dates=y}} {{use list-defined references|date=July 2022}} In [[computer science]], a '''smart pointer''' is an [[abstract data type]] that simulates a [[Pointer (computer programming)|pointer]] while providing added features, such as automatic [[memory management]] or [[bounds checking]]. Such features are intended to reduce [[Software bug|bugs]] caused by the misuse of pointers, while retaining efficiency. Smart pointers typically keep track of the memory they point to, and may also be used to manage other resources, such as network connections and [[file handle]]s. Smart pointers were first popularized in the programming language [[C++]] during the first half of the 1990s as rebuttal to criticisms of C++'s lack of [[automatic garbage collection]].<ref name="Kline_1997"/><ref name="Colvin_1994"/> Pointer misuse can be a major source of bugs. Smart pointers prevent most situations of [[memory leak]]s by making the memory deallocation automatic. More generally, they make [[object destruction]] automatic: an object controlled by a smart pointer is automatically destroyed ([[finalization|finalized]] and then deallocated) when the last (or only) owner of an object is destroyed, for example because the owner is a [[local variable]], and execution leaves the variable's [[scope (programming)|scope]]. Smart pointers also eliminate [[dangling pointer]]s by postponing destruction until an object is no longer in use. If a language supports automatic garbage collection (for example, [[Java (programming language)|Java]] or [[C Sharp (programming language)|C#]]), then smart pointers are unneeded for reclaiming and safety aspects of memory management, yet are useful for other purposes, such as [[Cache (computing)|cache]] data structure residence management and [[resource management]] of objects such as file handles or [[network socket]]s. Several types of smart pointers exist. Some work with [[reference counting]], others by assigning ownership of an object to one pointer.
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)