Does a c++ program automatically free memory when it crashes?

后端 未结 2 1389
孤城傲影
孤城傲影 2021-01-05 11:00

I read in Google c++ coding standards that Google does not use exception. If exception is not used, how do you free memory when errors occur in your program?

For ex

相关标签:
2条回答
  • 2021-01-05 11:06

    The operating system cleans up all used memory and file handles when a process is terminated for whatever reason.

    0 讨论(0)
  • 2021-01-05 11:10

    I have heard that some memory types like, on Windows, COM global heap memory cannot be freed for you. However, most memory/handles are cleaned up, because the OS has to cope with the condition that your application crashed. You can certainly guarantee it in the case of process-local memory and most handles like file handles, etc. In the general case, you can assume that the OS will clean up after you when your application exits.

    Also, don't ever, ever follow Google's style guide. It's not for C++, it's for C++ minus everything you have to take away to make it C. It might work for Google (dubiously), but it definitely won't work for anyone else.

    0 讨论(0)
提交回复
热议问题