3 ms·
In some instances of cyclic references, specifically those in which only one of the objects need be stack-allocated and in which none of the objects will be pas
by ekiru 17y ago
In some instances of cyclic references, specifically those in which only one of the objects need be stack-allocated and in which none of the objects will be passed into a higher scope. For example, one may find it useful in a tree class to keep a reference to each node's parents. Despite this cyclic reference, however, if you have a local variable which holds the top node of a tree it will, upon leaving scope, be destroyed. If its destructor recursively deletes the subtrees, RAII works despite the circular references.
However, you're right that in more complex scenarios, RAII doesn't deal with reference cycles.
The ideal situation would be a language in which one could use either garbage collection or static allocation with RAII as the situation demands.