C++ has deterministic finalization. When you declare a stack-based object, at the end of the scope, the destructor is called before other work is done.

I just finished writing a response on this topic for a customer, and thought I'd share my favorite reference on the subject with you: