I really like scope-based memory management (SBMM), or RAII, as it is more commonly (confusingly?) referred to by the C++ community. As far as I know, except for C++ (and C), there's no other mainstream language in use today that makes SBMM/RAII their main memory management mechanism, and instead they prefer to use garbage collection (GC).
I find this rather confusing, since
- SBMM makes programs more deterministic (you can tell exactly when andan object is destroyed);
- in languages that use GC you often have to do manual resource management (see closing files in Java, for example), which partly defeats the purpose of GC and is also error prone;
- heap memory can also (very elegantly, imo) be scope-bound (see
std::shared_ptr
in C++).
Why is not SBMM more widely used? What are its disadvantages?