+ 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?

16th Feb 2018, 3:23 PM
Andrija Dinic
Andrija Dinic - avatar
3 Respostas
+ 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.
16th Feb 2018, 5:22 PM
Ravi Chandra Enaganti
Ravi Chandra Enaganti - avatar
0
I see, thanks :)
16th Feb 2018, 5:23 PM
Andrija Dinic
Andrija Dinic - avatar