]> git.proxmox.com Git - rustc.git/blob - src/doc/nomicon/obrm.md
Imported Upstream version 1.3.0+dfsg1
[rustc.git] / src / doc / nomicon / obrm.md
1 % The Perils Of Ownership Based Resource Management (OBRM)
2
3 OBRM (AKA RAII: Resource Acquisition Is Initialization) is something you'll
4 interact with a lot in Rust. Especially if you use the standard library.
5
6 Roughly speaking the pattern is as follows: to acquire a resource, you create an
7 object that manages it. To release the resource, you simply destroy the object,
8 and it cleans up the resource for you. The most common "resource" this pattern
9 manages is simply *memory*. `Box`, `Rc`, and basically everything in
10 `std::collections` is a convenience to enable correctly managing memory. This is
11 particularly important in Rust because we have no pervasive GC to rely on for
12 memory management. Which is the point, really: Rust is about control. However we
13 are not limited to just memory. Pretty much every other system resource like a
14 thread, file, or socket is exposed through this kind of API.