Memory Leaks
There is no doubt about the fact that new and delete are very useful. But they have an associated problem that it is easy to forget to delete something that was previously allocated with new , leaving an orphaned memory block. A block that is still allocated but which has nothing referencing it.
A certain function that dynamically allocates memory to some object but forgets to deallocate the reserved memory, consumes some amount of memory every time it is executed. Thus a part memory disappears with its every run, and eventually the amount of memory consumed has an adverse affect on the system. This situation is called as a Memory Leak.
Many possible reasons that lead to the situation of memory leaks. Most common of these are:
1) forgetting to delete something that has been dynamically allocated using new operator.
2) Failing to notice that code may bypass a delete statement under certain circumstances.
3) Assigning the result of a new statement to a pointer that was already pointing to an allocated object.
Note:
Improper use of new and delete may lead to memory leaks. Make sure the memory allocated through “new” must be properly deleted through “delete”.