Giving objects responsibility for resources
Files, dynamic allocations, and sockets require timely release. RAII gives a management object responsibility for a resource: initialization establishes its valid state and destruction performs the associated cleanup.
The handle can be a local variable or a member of another object. A C++ smart pointer can manage data allocated on the heap. RAII concerns ownership and cleanup timing, not a requirement that the resource itself reside on the call stack.
Sharing cleanup across exit paths
During ordinary C++ scope exit and exception unwinding, applicable automatic objects are destroyed according to language rules. Resource handles let multiple return and throwing paths share cleanup instead of duplicating release code at every exit.
Failed construction requires distinguishing the incomplete object from its fully constructed subobjects. C++ destroys the completed subobjects. Giving members ownership of resources therefore makes failure handling easier to structure than leaving acquisitions as unmanaged addresses in an outer constructor.
Cleanup is not arbitrary rollback
Releasing a handle does not automatically undo external writes or establish a strong exception guarantee. Coordinated state changes still require commitment, rollback, and failure-reporting contracts, including suitable behavior from cleanup itself.
Automatic destruction depends on the exit mechanism. Rust likewise distinguishes ordinary dropping from explicit suppression and termination without unwinding. Lifetime-based management does not promise that every crash, forced termination, or external failure executes all cleanup.