In C ++, I need to free memory before closing the program

Possible duplicate:
Is it allowed to free memory

This is a common question. I have several projects on the C ++ desktop that work with some global data structure. My question is, before exiting the applications, do I need to free memory for these data structures? In any case, the memory will be destroyed by the OS after closing the application.

+3
source share
4 answers

Short answer: No ( Yes , if you are pedantic enough (that's good) ... see edit)

All memory allocated by the program will be automatically freed by the operating system when the program exits.

, , , , .

. @David Thornley , . , , , , , . , , , , .

+7

, ​​, , alocate, . , , valgrind

+3

, . Undefined ++. .

+2

, , , , . , , .

If you know exactly what global objects you leave hanging in the end, then this is absolutely normal.

It may be good practice to always write code that stops completely so as not to miss actual leaks; it just depends on your confidence in your code.

+2
source

Source: https://habr.com/ru/post/1616837/


All Articles