Content deleted Content added
m clean up; MOS:OVERLINK |
better ref for Vala |
||
Line 9:
| access-date=2019-03-09}}</ref> is a [[programming idiom]]<ref>{{cite book |last1=Sutter |first1=Herb |author-link1=Herb Sutter |last2=Alexandrescu |first2=Andrei |author-link2=Andrei Alexandrescu |year=2005 |title=C++ Coding Standards |url=https://archive.org/details/isbn_0321113586 |url-access=limited |series=C++ In-Depth Series |publisher=Addison-Wesley |page=[https://archive.org/details/isbn_0321113586/page/n54 24] |isbn=978-0-321-11358-0 }}</ref> used in several [[Object-oriented programming|object-oriented]], [[Statically-typed programming language|statically-typed]] programming languages to describe a particular language behavior. In RAII, holding a resource is a [[class invariant]], and is tied to [[object lifetime]]: [[Resource allocation (computer)|resource allocation]] (or acquisition) is done during object creation (specifically initialization), by the [[Constructor (object-oriented programming)|constructor]], while resource deallocation (release) is done during object destruction (specifically finalization), by the [[Destructor (computer programming)|destructor]]. In other words, resource acquisition must succeed for initialization to succeed. Thus the resource is guaranteed to be held between when initialization finishes and finalization starts (holding the resources is a class invariant), and to be held only when the object is alive. Thus if there are no object leaks, there are no [[resource leak]]s.
RAII is associated most prominently with [[C++]] where it originated, but also [[D (programming language)|D]],<ref>{{cite web |title=Scope guards |url=https://tour.dlang.org/tour/en/gems/scope-guards |website=Dlang Tour |access-date=21 May 2021}}</ref> [[Ada (programming language)|Ada]],<ref>{{cite web |title=Gem #70: The Scope Locks Idiom |url=https://www.adacore.com/gems/gem-70 |website=AdaCore |access-date=21 May 2021 |language=en}}</ref> [[Vala (programming language)|Vala]],<ref>{{
| url=https://stackoverflow.com/a/99986
| title=How do you pronounce RAII?
|