White Box Testing
Test your code
   Home      MemoryLeakTesting
 
Memory Leak 
 
A memory leak is unintentional memory consumption where the program fails to release memory when no longer needed. A memory leak decreases the performance of the system by reducing the amount of available memory.As a result, the program consume more and more memory until it finally crashes because there is no more memory left.
 
Typically memory leak occurs when dynamically (Heap area) allocated memory unreachable. There are different ways of defining lifetime of the heap.These can be classified into three main categories, based on the following heap properties:
 
1. Referencing: the lifetime of a cell ends when it there are no references to that cell . This notion is used, for instance, by reference-counting garbage collectors.
 
2. Reachability: the lifetime of a cell ends when it is no longer reachable from program variables. This notion is used by tracing and copying garbage collectors.
 
3. Liveness: the lifetime of a cell ends after the last access to that cell. This is the most precise notion of lifetime.
 
Complex programs always have memory leaks. These can’t be avoided in development cycle.
 
 
Why are memory errors hard to debug?
 
Why memory errors are different from other bugs. The main reason is that they are fragmented and fragile. By fragmented means the point where you will see the resource leak is not actual point and may be there is a resource leak in a complex object but resource leak shown only object containing by this complex object. By fragile, I mean the bug will often only show up under certain conditions, and that attempts to isolate the bug by changing the program or its input often mask its effects.
 
To isolate bug make your program or test code modular.
 
Resource leak testing should be done in bottom up approach (or backward analysis)   
 
 
Vulnerable areas for memory leaks:
  • Embedded system where memory size restricted.
  • Program or application is left running consuming more and more memory over time.
  • Program is able to request memory that is not released, even when the program terminates (ex shared memory).
  • Leaks inside the operating system and other system resource.
 
Effects on system:
  • Memory leaks degrade performance due to increased paging.
  • Over time, cause a program to run out of memory and crash.
  • Access errors lead to data corruption, which causes a program to behave incorrectly or crash.
  • When a program runs out of memory it also can cause the OS kernel to crash.
 
 
 

External References