Resource leak
In computer science, a resource leak is a particular type of resource consumption by a computer program where the program does not release resources it has acquired. This condition is normally the result of a bug in a program. Typical resource leaks include memory leak and handle leak, particularly file handle leaks, though memory is often considered separately from other resources.[1]
Examples of resources available in limited numbers to the
Resource leaks are particularly a problem for resources available in very low quantities. Leaking a unique resource, such as a lock, is particularly serious, as this causes immediate resource starvation (it prevents other processes from acquiring it) and causes deadlock. Intentionally leaking resources can be used in a denial-of-service attack, such as a fork bomb, and thus resource leaks present a security bug.
Causes
Resource leaks are generally due to programming errors: resources that have been acquired must be released, but since release often happens substantially after acquisition, and many things may occur in the meantime (e.g., an exception being thrown or abnormal program termination) it is easy for release to be missed.
A very common example is failing to close files that have been opened, which leaks a file handle; this also occurs with
Prevention and mitigation
Resource leaks can be prevented or fixed by resource management: programming techniques or language constructs may prevent leaks by releasing resources promptly, while a separate process may reclaim resources that have been leaked. Many resource leaks are fixed by resource reclamation by the operating system after the process terminates and makes an exit
system call.
Resource leaks are thus primarily a problem for long-lived processes, as leaked resources held by still-running processes are often not reclaimed; and for processes that rapidly acquire and leak many resources.
See also
- Resource starvation
- Software aging
References
- ISBN 9780132465915.
- ISBN 9780735671300.
- ISBN 9780789715395.