Even in a reference counted or RAII environment, you still have to think about this. Your C++ function might do something with a file (or other resource) and then a bunch of other stuff, or vice-versa. If you care about holding that resource open for as little time as possible, you need to consciously introduce a new anonymous scope where the resource object and operations are contained (or, of course, you could break it out into another function).