Global objects with local variables
Variables and Namespace
I’ve recently had a noticeable conversation explaining a junior colleague of mine about local variables in hierarchy of calls, namespace and scope, and how this concept aligns with Object-Oriented Programming, dynamically created / released object instances, in particular.
Below is the scheme I ended with.
Lifespan of objects
If lifespan of a variable is defined by its scope, lifespan of an object is defined from when it’s been created till when it’s been released. However, if an object was not explicitly released, it might be (not guaranteed!) released automatically when the last pointing to it variable goes out of scope (read more about Garbage Collector objects).