I was wondering if someone could shed some light on the deallocation-of-memory processes in c++.
If I have a struct that I declare static, such that it's constructor is the first thing to execute and its destructor is the last thing to execute:
struct initializer execute_before_and_after_main {
initializer() { init(); }
~initializer() { cleanup(); }
}
static initializer execute_around_main;
And I then have something like:
class my_class {
my_object objects[100];
}
extern my_class gobal_my_class;
my_class global_my_class;
and main is not important here:
int main (int argc, char* argv[]) {
....
}
When cleanup()
is called, is the objects
array now containing deallocated/invalid memory? Is there a standard sequence of initialisation/destruction that c++ implements here that someone could perhaps point me to?
Thanks
EDIT: I understand this type of code is possibly not the best practice, but I am still wondering if the behaviour is defined.