+ 2
If you dynamically allocate variable in C++, and for some reason, program exits, does variable remain in memory?
Let's say you dynamically allocate int variable. You use raw pointers. Let's say, after creation, error occurres and program exits without calling delete on pointer. Would that variable remain stored in memory until you restart your computer or would compiler free the memory?
3 ответов
+ 3
If your program exits, even if you don't delete dynamically allocated memory, it gets destroyed along with the program memory. However of your program runs as a background service, this causes some serious problem like slowing down your system by consuming the memory and finally crashing the system.
0
I see, thanks :)