+ 1
Please anyone explain what does "Memory Leaks" mean in Programming?
I hope you all are doing great in your lives. Kindly help me to understand the concept of memory leaks. When/Where/Why we need it?
3 ответов
+ 2
We always try to avoid memory leaks. So let's say that you created the pointer and never deleted it. Dynamic objects (pointers) are created on Heap, and heap has very big disadventage. Programmer has to clean it himself. So going back to our pointer, if we won't delete it, it will always remain in RAM, taking some of its memory. And if some memory cell is used, you cannot allocate memory for next object that you would like to use.
So going back to your question: What is memory leak? It's when you allocate some memory, but never release it for further usage.
Hope I helped you with understanding the problem ^^
+ 2
I'm glad you tagged c++. Memory leaks are easy there and part of the reason Java was invented, which can still leak memory, but usually in complicated ways behind the scenes when failing to release resources.
In C++ you create objects on the heap with the new keyword. If you don't delete them they remain in memory. When this happens and you have lost the reference (pointer) to them, you have a leak. Long running systems can fail, or fail over the whole system because of this.
0
Oh and coming back to pointers in standard of C++ (11) authors has introuduced smart pointers, they work in the same way as pointers, but you do not have to worry about deleting it :)