HOME

TheInfoList



OR:

In
computer science Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
, a resource leak is a particular type of
resource ''Resource'' refers to all the materials available in our environment which are Technology, technologically accessible, Economics, economically feasible and Culture, culturally Sustainability, sustainable and help us to satisfy our needs and want ...
consumption by a
computer program A computer program is a sequence or set of instructions in a programming language for a computer to Execution (computing), execute. It is one component of software, which also includes software documentation, documentation and other intangibl ...
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 In computer science, a memory leak is a type of resource leak that occurs when a computer program incorrectly manages memory allocations in a way that memory which is no longer needed is not released. A memory leak may also happen when an objec ...
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 and software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ...
include internet sockets,
file handle In Unix and Unix-like computer operating systems, a file descriptor (FD, less frequently fildes) is a process-unique identifier (handle) for a file or other input/output resource, such as a pipe or network socket. File descriptors typically ha ...
s, process table entries, and
process identifier In computing, the process identifier (a.k.a. process ID or PID) is a number used by most operating system kernel (operating system), kernels—such as those of Unix, macOS and Windows—to uniquely identify an active Process (computing), process. ...
s (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 In computer science, resource starvation is a problem encountered in concurrent computing where a process is perpetually denied necessary resources ''Resource'' refers to all the materials available in our environment which are Technology, te ...
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 Lock(s) or Locked may refer to: Common meanings *Lock and key, a mechanical device used to secure items of importance *Lock (water navigation), a device for boats to transit between different levels of water, as in a canal Arts and entertainme ...
, 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 In computing, a denial-of-service attack (DoS attack) is a cyberattack in which the perpetrator seeks to make a machine or network resource unavailable to its intended users by temporarily or indefinitely disrupting services of a host co ...
, such as a
fork bomb In computing, a fork bomb (also called rabbit virus) is a denial-of-service (DoS) attack wherein a process continually replicates itself to deplete available system resources, slowing down or crashing the system due to resource starvation. ...
, and thus resource leaks present a
security bug A security bug or security defect is a software bug that can be exploited to gain unauthorized access or privileges on a computer system. Security bugs introduce security vulnerabilities by compromising one or more of: * Authentication of users ...
.


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 Pipe(s), PIPE(S) or piping may refer to: Objects * Pipe (fluid conveyance), a hollow cylinder following certain dimension rules ** Piping, the use of pipes in industry * Smoking pipe ** Tobacco pipe * Half-pipe and quarter pipe, semi-circu ...
. Another common example is a
parent process In computing, a parent process is a process that has created one or more child processes. Unix-like systems In Unix-like operating systems, every process except (the swapper) is created when another process executes the fork() system call. T ...
failing to call wait on a
child process A child process (CP) in computing is a process created by another process (the parent process). This technique pertains to multitasking operating systems, and is sometimes called a subprocess or traditionally a subtask. There are two major proce ...
, 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 stat ...
, leaking a process table entry.


Prevention and mitigation

Resource leaks can be prevented or fixed by
resource management In organizational studies, resource management is the efficient and effective development of an organization's resources when they are needed. Such resources may include the financial resources, inventory, human skills, production resources, or ...
: 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 and software resources, and provides common daemon (computing), services for computer programs. Time-sharing operating systems scheduler (computing), schedule tasks for ...
after the process terminates and makes an
exit Exit(s) may refer to: Architecture and engineering * Door * Portal (architecture), an opening in the walls of a structure * Emergency exit * Overwing exit, a type of emergency exit on an airplane * Exit ramp, a feature of a road interchange A ...
system call In computing, a system call (syscall) is the programmatic way in which a computer program requests a service from the operating system on which it is executed. This may include hardware-related services (for example, accessing a hard disk drive ...
. 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 In computer science, resource starvation is a problem encountered in concurrent computing where a process is perpetually denied necessary resources ''Resource'' refers to all the materials available in our environment which are Technology, te ...
*
Software aging In software engineering, software aging is the tendency for software to Software failure, fail or cause a system failure after running continuously for a certain time, or because of ongoing changes in systems surrounding the software. Software a ...


References

{{reflist Computational resources