It is essentially unique_ptr
vs shared_ptr
.
Single ownership, otherwise known as unique ownership, means that the resource is owned by a single class instance. Once that instance ceases to exist the resource is released (via the destructor). The majority of RAII classes you find have unique ownership, such as std::vector
.
Shared ownership means the resource is shared between multiple class instances. The resource is only released once every instance ceases to exist and thus requires some form of reference counting or garbage collection. An example of where you would want shared ownership is a handle to a very expensive to copy immutable resource. I've seen it used in graphs too.
It might help to think in terms of pointers. Single ownership will only have 1 owning pointer, shared will have multiple. Of course, RAII might not involve pointers.
+---------------+
|Shared instance|
+--------+ +------------+--+ +---------------+
|Resource| | +----------+Shared instance|
+--------+ v v +---------------+
^ +--------+
| |Resource|<-----------+
| +--------+ +---+-----------+
| ^ |Shared instance|
+------+--------+ | +---------------+
|Unique Instance| |
+---------------+ |
+------+--------+
|Shared instance|
+---------------+