Jump to content

Smart pointer

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Alfio (talk | contribs) at 18:22, 16 September 2003 (new article). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

In computer programming, a smart pointer is a pointer that keeps track of the pointer object for the purpose of memory management.

Pointer usage is a major source of bugs: the constant allocation, deallocation and referencing that must be performed by a program written using pointers makes it very likely that some memory leaks will occur.

Smart pointers try to prevent the memory leaks making the deallocation function automatic: when the pointer to an object (or the last in a series of pointers) is destroyed, for example because it goes ouside of scope, the pointed object is destroyed too.

Several types of smart pointers exist. Some works with reference counting, others assigning onwership of the object to a single pointer.

See also: Garbage collection