If the program keeps allocating memory and doesnt
return it all, eventually
all the memory in the system will be used up.
For example:
for( int i = 0; i < size; i++ ) // the memory reserved for x is returned to
the
{ //
stack when x goes out of scope }
int x = 5;
}
for( int i = 0; i < size; i++ ) // The pointer goes
out of scope but the memory
{ //
it pointed too is still reserved
int* x = new int(5);
// But now we have lost its address, there is no
} //
way to find it again it is orphaned memory
If this occurs enough times the system will crash for
lack of unallocated
memory.
During GWI the patriot missile systems had to be
shutdown and restarted
every few hours because their control system had a memory leak.