0

I am working with a program where my code calls a third party library which uses boost and shared_pointers to create a large and complex structure. This structure is created in a method that I call and at the end of the method I know that the program is finished. For a large sample that I am handling the code to handle the processing takes 30 minutes and the boost code called automatically at exit takes many hours. Exiting the program without releasing the memory and spending all that time would be a perfectly acceptable outcome. I tried vector *iddListV = new vector(); // this WILL leak memory with all the relevant structures added to the vector but this does not help. I also tried calling exit(0); before reaching the end of the subroutine. This also causes the boost code to spend many hours trying to release pointers. How to I get a C++ program (Microsoft C++ on Windows if that matters) to abruptly exit without calling the boost destructors. My constraints are I can call any function before the boost structure are allocated but cannot modify the code once it starts running.

4
  • I use the C++11 versions, but does boost let you provide a custom deleter? Commented Apr 3, 2013 at 21:34
  • @chris yes, there is boost doc Commented Apr 3, 2013 at 21:42
  • Curious, have you tried profiling to see why there's an issue? Commented Apr 3, 2013 at 23:15
  • running in the debugger pausing the program after the code is done and exiting the function always stops at some level of a boost destructor. Commented Apr 8, 2013 at 20:50

3 Answers 3

1

_Exit quits without calling any destructors.

Sign up to request clarification or add additional context in comments.

Comments

0

If you're unconcerned about portability, you can call TerminateProcess(). But remember to take care that you are absolutely sure that your program is in a state which is ready to terminate. For example, if you terminate before I/O has had a chance to flush, then your file data and network streams may become invalid.

Comments

0

It is possible, in a portable manner, to do:

#include <exception>
...
std::terminate();

However, there's a big gotcha, in that, at least on linux, this may cause a core dump. (I'm really not sure what the behavior is on Windows).

It should be noted, that the behavior is implementation defined as far as whether or not destructors are called. Siting §15.5.1 P2:

In the situation where the search for a handler (15.3) encounters the outermost block of a function with a noexcept-specification that does not allow the exception (15.4), it is implementation-defined whether the stack is unwound, unwound partially, or not unwound at all before std::terminate() is called.

Additionally in §18.8.3.4 P1:

Remarks: Called by the implementation when exception handling must be abandoned for any of several reasons (15.5.1), in effect immediately after evaluating the throw-expression (18.8.3.1). May also be called directly by the program.

C++11 also defines the function std::quick_exit(int status) that can be used in a similar manner (presumably without a coredump). This function is available from <cstdlib>.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.