Possible duplicate:What REALLY happens when you don't get t after malloc?
At the end of a C / C ++ program, you must clear by freeing the pointers. What happens if you do not free memory, for example, if you have a pointer to int and does not delete it when the program terminates? Is the memory still in use and can only be freed upon reboot or is it freed automatically when the program ends? And in the latter case, why free it if the operating system does it for you?
When your program ends, all memory will be freed by the operating system.
, , , . , , . , , . , , . .
, ( ) . - , , , , , , , , .
, Windows, Linux MacOS, .
.
, - , . , .
- , main(), , , . , , - .
main()
, , , , .
: 1) , 2) ++, "" ed- "" d, , ( , , , )
Itβs important to free up memory correctly so that the tools that helped you find memory leaks will have a meaningful result when you need to track problems. Allowing the OS to free memory for you will add extra noise to any analytic tools that you can use later. Even if the OS returns memory to the system, you must have a solid design that uses memory properly and allows you to make the best use of tools.