Been reading C++ books but I can't seem to find the answer. All I know is dynamic memory allocation such as when I make a function:
void memoryleak(){ int * ptr = new int; } It allocates a memory and returns that memory to the pointer, however, since the pointer is a local variable, after the memoryleak(), the pointer which contains the reference of the memory was deallocated because it's static, hence the allocated memory is lost and cannot be reused for the program.
But does it mean the memory is lost forever or only until the program is terminated like after compiling this code snippet:
main(){ int * ptr = new int; } After the program terminates, will the memory stay allocated or deallocated? If it stays allocated, does restarting the PC make the PC deallocate all used memory? Another question, out of curiosity, about the memory which they use (in allocation), is it RAM? :)