In
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to practical disciplines (includin ...
, a resource leak is a particular type of
resource consumption by a
computer program
A computer program is a sequence or set of instructions in a programming language for a computer to execute. Computer programs are one component of software, which also includes documentation and other intangible components.
A computer progra ...
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.
Examples of resources available in limited numbers to the
operating system
An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ef ...
include
internet sockets,
file handles,
process table entries, and
process identifiers (PIDs). Resource leaks are often a minor problem, causing at most minor slowdown and being recovered from after processes terminate. In other cases resource leaks can be a major problem, causing
resource starvation and severe system slowdown or instability, crashing the leaking process, other processes, or even the system. Resource leaks often go unnoticed under light load and short runtimes, and these problems only manifest themselves under heavy system load or systems that remain running for long periods of time.
[.]
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
pipes. Another common example is a
parent process failing to call
wait
Wait or WAIT may refer to:
Music
* Wait (musician), British town pipers
Albums and EPs
* ''Wait'' (The Polyphonic Spree EP), by The Polyphonic Spree
* ''Wait'' (Emanuel Nice EP), a 2002 EP released by the band Emanuel Nice
* ''Wait'' (Stee ...
on a
child process, which leaves the completed child process as a
zombie process
On Unix and Unix-like computer operating systems, a zombie process or defunct process is a process that has completed execution (via the exit system call) but still has an entry in the process table: it is a process in the " Terminated state ...
, leaking a
process table entry.
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
An operating system (OS) is system software that manages computer hardware, software resources, and provides common daemon (computing), services for computer programs.
Time-sharing operating systems scheduler (computing), schedule tasks for ef ...
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
{{reflist
Computational resources