Conceptual
Login

Drop Order and Resource Acquisition Is Initialization

Values are cleaned up in the reverse of the order they were created, so the thing you set up last is torn down first. Tying a resource's life to a value's life — take it when you build the value, release it when the value dies — is a pattern old enough to have a clumsy name, but it is simply how you stop leaks. When you need cleanup in a particular order, you control it by controlling the order things were created.

Questions this Concept answers

  • Why does reverse destruction order matter to a driver's teardown?