Will exit() or an exception prevent an end-of-scope destructor from being called?

If you call exit, the destructor will not be called. From the C++ standard (ยง3.6.1/4): Calling the function void exit(int); declared in <cstdlib> (18.3) terminates the program without leaving the current block and hence without destroying any objects with automatic storage duration (12.4). If exit is called to end a program during the destruction of … Read more

How to destroy an object?

You’re looking for unset(). But take into account that you can’t explicitly destroy an object. It will stay there, however if you unset the object and your script pushes PHP to the memory limits the objects not needed will be garbage collected. I would go with unset() (as opposed to setting it to null) as … Read more

What destructors are run when the constructor throws an exception?

if a constructor throws an exception, what destructors are run? Destructors of all the objects completely created in that scope. Does it make any difference if the exception is during the initialization list or the body? All completed objects will be destructed. If constructor was never completely called object was never constructed and hence cannot … Read more

Is destructor called if SIGINT or SIGSTP issued?

No, by default, most signals cause an immediate, abnormal exit of your program. However, you can easily change the default behavior for most signals. This code shows how to make a signal exit your program normally, including calling all the usual destructors: #include <iostream> #include <signal.h> #include <unistd.h> #include <cstring> #include <atomic> std::atomic<bool> quit(false); // … Read more