Memory Leaks
What is Memory Leak?
Memory leaks occur when we allocate memory using new
but forget to deallocate it before the pointer to this memory goes out of scope.
How does it occur?
Sometime we might remember to deallocate the memory but use the wrong delete syntax.
This does not throw an error. But leaves both the variable and the array undeleted.
Arrays should use delete []
and varibales should use delete
What are the risks?
Decrease the performance
In worst case, no more space is left; program/system crashes
More at risk: Video games, small embedded devices, device drivers, programs allocating and deallocating too frequently
Last updated