Answer includes the issues occur due to memory leak in C,C++ project. This is a very important technical interview question asked for any languages i.e. C, C++, Java and C# etc. that we should prepare.
This answer contains issues due to memory leaks in C / C++ project I have faced. However, It is applicable to all and will give you an idea to answer this question.
Answer: I Have faced application hang and process crash issues due to memory leaks in my C++ software projects. We know that if we dynamically allocate memory on heap using new operator or malloc() function and forget to de-allocate the previously allocated memory, then there will be a memory leak problem in the program or application.
When the piece of code in a program having memory leaks is getting called again and again or may be in loops, then program will fill the system memory gradually. And that memory will be of no use. No same program or other programs will be able to use this leaked memory again until we restart the machine.
Scenarios- Issues faced due to memory leak in C++ project:
- Application hang: There was a function that was reading data (500 KB) from USB port continuously in a loop every 1 seconds and had a memory leak for 500 KB. As a result, it was filling system memory continuously and we had limited memory of 512 MB. After some hours of execution memory was getting occupied until it reaches up to 512 MB due to memory leak resulting hang as there was no memory for further allocation. So, only option to restart the machine.
- Process Crash: Some processes was performing file IO operations (file read and copy etc.). And, we know that when program performs some operations on files, it get loaded into memory. Since, all memory was filled due to memory leak, it was getting memory violation as it did not have any more memory space to load the file.
NOTE: If a piece of code in a program have memory leak and have repetitive call in a loop, issue of memory leak can be easily seen.