I set a breakpoint in a destructor, which only gets called, when the program finishes completely. Now I start the program with CLion's debugger, but it never reaches the destructor. When I press on finish in CLion the debugger closes and the breakpoint never gets reached. How can I reach the breakpoint in the destructor in CLion?
Asked
Active
Viewed 860 times
0
-
Without knowing the relevant code it is not really possible to tell. Do other breakpoints work? If yes you probably have optimizations turned on and the compiler is might optimize everything in the destructor away, or at least that much that the breakpoint does not work. – t.niese Jul 30 '19 at 13:21
-
Other breakpoints work, but the only way to reach the breakpoint in the destructor is to close the debugger in clion, which ofc well closes the debugger. – Hakaishin Jul 30 '19 at 14:11
-
You need to finish the program and not the debugger to reach the breakpoint in the destructor. – Jan Deinhard Jul 30 '19 at 20:54
-
I know, the question is how? – Hakaishin Jul 30 '19 at 22:38
-
@Hakaishin, depends very much on your program. Is it possible to make it quit when hitting a key? – Jan Deinhard Jul 31 '19 at 10:42
-
Usually I press ctrl + c, but this does not work in the clion environment – Hakaishin Aug 05 '19 at 11:11
-
Can you send a signal to it with `kill
`? – Victor Sergienko Aug 09 '19 at 21:35
1 Answers
0
You need to find a way to stop looping in your main thread, and jump to return 0;
at the end of your int main(...) {
. Alternatively, you can use exit(0)
, I believe. (Source: Difference between "return 0" and "exit (0)")
There's more:
You need to share your code, but there's this information, which you may find useful:
Please see these references:
Are Basic Object Destructors Called On Exit()?
Note that objects with automatic storage are not destroyed by calling exit (C++). http://www.cplusplus.com/reference/cstdlib/exit/
The problem could be that, during exit, your destructor is never called, anyway. Hence, it is a leak but the OS will handle it.

Community
- 1
- 1

Okan Barut
- 279
- 1
- 7