Content deleted Content added
Added reference for who recommends RAII |
Psiĥedelisto (talk | contribs) |
||
Line 109:
Ownership of dynamically allocated objects (memory allocated with <code>new</code> in C++) can also be controlled with RAII, such that the object is released when the RAII (stack-based) object is destroyed. For this purpose, the [[C++11]] standard library defines the [[smart pointer]] classes <code>[[Smart pointer#unique_ptr|std::unique_ptr]]</code> for single-owned objects and <code>[[Smart_pointer#shared_ptr_and_weak_ptr|std::shared_ptr]]</code> for objects with shared ownership. Similar classes are also available through <code>[[auto ptr|std::auto_ptr]]</code> in C++98, and <code>boost::shared_ptr</code> in the [[Boost (C++ libraries)|Boost libraries]].
==
Both [[Clang]] and the [[GNU Compiler Collection]] implement a non-standard extension to the [[C (programming language)|C]] language to support RAII: the "cleanup" variable attribute.<ref>{{Cite web
| url=https://gcc.gnu.org/onlinedocs/gcc/Variable-Attributes.html
| title=Specifying Attributes of Variables
|