A handle leak is a type of
software bug
A software bug is a design defect ( bug) in computer software. A computer program with many or serious bugs may be described as ''buggy''.
The effects of a software bug range from minor (such as a misspelled word in the user interface) to sev ...
that occurs when 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 ...
asks for a
handle
A handle is a part of, or an attachment to, an object that allows it to be grasped and object manipulation, manipulated by hand. The design of each type of handle involves substantial ergonomics, ergonomic issues, even where these are dealt wi ...
to a
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 ...
but does not free the handle when it is no longer used.
If this occurs frequently or repeatedly over an extended period of time, a large number of handles may be marked in-use and thus unavailable, causing
performance problems or a
crash.
The term is derived from
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 ...
. Handle leaks, like memory leaks, are specific instances of
resource leaks.
Causes
One cause of a handle leak is when a programmer mistakenly believes that retrieving a handle to an entity is simply obtaining an unmanaged
reference
A reference is a relationship between objects in which one object designates, or acts as a means by which to connect to or link to, another object. The first object in this relation is said to ''refer to'' the second object. It is called a ''nam ...
, without understanding that a count, a copy, or other operation is actually being performed. Another occurs because of poor
exception handling
In computing and computer programming, exception handling is the process of responding to the occurrence of ''exceptions'' – anomalous or exceptional conditions requiring special processing – during the execution of a program. In general, an ...
design pattern
A design pattern is the re-usable form of a solution to a design problem. The idea was introduced by the architect Christopher Alexander and has been adapted for various other disciplines, particularly software engineering. The " Gang of Four" ...
s when programmers do not consider that when an exception occurs and a sub routine is exited prematurely, the cleanup code at the end of the routine may not be executed.
An example of this might be retrieving a handle to the display device. Programmers might use this handle to check some property (e.g. querying the supported resolutions), and then simply proceed on without ever releasing the handle. If the handle was just a pointer to some data structure with no additional management, then allowing the handle to pass out of scope would not cause an issue. However, in many cases, such handles must be explicitly closed or released to avoid leaking resources associated with them; the exact requirements for what must be done with a handle varies by interface.
References
Software bugs
{{Compu-prog-stub