Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can end up needing a lot of different RAII types, which can get a bit annoying. If you're trying to interface with anything that wasn't written with RAII in mind - e.g., any library that tries to be C-compatible - this is pretty much inevitable.

In theory, doing without is a huge problem, because you're running the risk of resource leaks and stale identifiers - but in practice, neither is a huge problem. Picking these sorts of bugs out has been pretty simple in every project I've worked on. I've had far more heartache from the bugs stemming from RAII-type mechanisms holding on to resources longer than they should, than I've had from fixing bugs caused by resource leaks or stale resource identifiers.



With std::unique_ptr (you can set the deleter) and ScopeGuard you don't need to create new types for every type of resource.

I respectfully disagree with leaks not being a problem.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: