0% found this document useful (0 votes)
64 views4 pages

Memory Leakage: Sunbeam Infotech

Memory leakage occurs when a program fails to release dynamically allocated memory after it is no longer needed. This unused memory cannot be used by the program or operating system, reducing available RAM. While the leaked memory will be automatically released when the program terminates, it is still a concern for long-running programs. Tools like valgrind can detect memory leaks, and modern programming techniques like smart pointers in C++ help prevent leaks from occurring.

Uploaded by

Kiran Belle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views4 pages

Memory Leakage: Sunbeam Infotech

Memory leakage occurs when a program fails to release dynamically allocated memory after it is no longer needed. This unused memory cannot be used by the program or operating system, reducing available RAM. While the leaked memory will be automatically released when the program terminates, it is still a concern for long-running programs. Tools like valgrind can detect memory leaks, and modern programming techniques like smart pointers in C++ help prevent leaks from occurring.

Uploaded by

Kiran Belle
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Memory Leakage

#technicalthursday
Sunbeam Infotech
Sunbeam Infotech www.sunbeaminfo.com
Memory leakage

• Dynamically allocated memory must be released by the applicaition.


• In C, memory allocated by malloc() must be released by free().
• In C++, memory allocated by new operator must be released by delete operator.
• If dynamically allocated memory is not released by the application, it is referred as
"Memory Leakage".

void fun() { 5
base address is so this memory 24 bytes allocated
1 int *p;
stored in pointer. 10 is leaked. by malloc().
3 p = (int*) malloc(24); p
4
// … 2

6 // free(p); not called. on stack 400


}
9 500 400 on heap
7
// fun() returns. 8
pointer is destroyed so memory is
when fun() returns. not released.

. Sunbeam Infotech www.sunbeaminfo.com


Memory leakage
• Memory leakage is a programmer's mistake.
• Programmer forget to release the memory and pointer variable holding the address is destroyed.
• The pointer variable is overwritten with some other address (and allocated address is lost).
• Leaked memory cannot used by the application or operating system. It reduces
available RAM size. This may slow down whole system performance.
• This leaked memory is automatically released when application is terminated.
• However this is still a concern for long running applications (e.g. web servers, mail
servers, mobile applications, system services, etc).
• The valgrind tool on Linux is used to detect memory leakage.
• The memory profilers can be used for the same on Windows.
• Modern C++ heavily relies on smart pointers to avoid memory leakage.
• COM and Linux kernel use reference counting to release unused objects.
• Languages like Python, Java and C# use garbage collection for the same.
. Sunbeam Infotech www.sunbeaminfo.com
Thank you!
Sunbeam Infotech

Sunbeam Infotech www.sunbeaminfo.com

You might also like