They say that dynamically allocated memory is returned only to you, the programmer. For instance,
myclass *obj = new myclass();
must always have appropriate
delete obj;
somwehere, otherwise your program will be a memory leak, which means that the operating system may think that certain parts of the memory are used when in fact it is not - after too many leaks your memory may be exhausted completely with false memory, and you won " I canβt do anything about it. "
However, βC ++β (effectively meaning βcompilerβ) takes care of everything that you allocate on the stack, for example
myclass obj;
while your destructors actually correctly delete everything that you dynamically create inside this class.
However, in practice, if you miss memory, modern operating systems will take care of this and, as a rule, will clear it. Usually there is some kind of system where the OS can recognize which parts of the used memory you are actually using, and then just free everything there as soon as the application is completed.
Memory leaks usually only really cause problems when your application needs so much memory that it needs to be fixed from time to time, or when you continuously leak memory in a loop (like games), on systems with limited memory (like consoles )
source share