A Simple Example in C
The following C function deliberately leaks memory by losing the pointer to the allocated memory. Since the program loops forever calling the memory allocation function, malloc
, but without saving the address, it will eventually fail (returning NULL
) when no more memory is available to the program. Because the address of each allocation is not stored, it is impossible to free any of the previously allocated blocks. It should be noted that, generally, the operating system delays real memory allocation until something is written into it. So the program ends when virtual addresses run out of bounds (per process limits or 2 to 4 GiB on IA-32 or a lot more on x86-64 systems) and there may be no real impact on the rest of the system.
Read more about this topic: Memory Leak
Famous quotes containing the word simple:
“The ordinary literary man, even though he be an eminent historian, is ill-fitted to be a mentor in affairs of government. For ... things are for the most part very simple in books, and in practical life very complex.”
—Woodrow Wilson (18561924)