Handle leak
Encyclopedia
A handle leak is a type of software bug
that occurs when a computer program
asks for a handle
to a resource
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 problem
s or a crash
.
The term is derived from memory leak
. Handle leaks, like memory leaks, are specific instances of resource leak
s.
, without understanding that a count, a copy, or other operation may actually be being performed.
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.
Software bug
A software bug is the common term used to describe an error, flaw, mistake, failure, or fault in a computer program or system that produces an incorrect or unexpected result, or causes it to behave in unintended ways. Most bugs arise from mistakes and errors made by people in either a program's...
that occurs when a computer program
Computer program
A computer program is a sequence of instructions written to perform a specified task with a computer. A computer requires programs to function, typically executing the program's instructions in a central processor. The program has an executable form that the computer can use directly to execute...
asks for a handle
Handle (computing)
In computer programming, a handle is a particular kind of smart pointer. Handles are used when application software references blocks of memory or objects managed by another system, such as a database or an operating system....
to a resource
Resource (computer science)
A resource, or system resource, is any physical or virtual component of limited availability within a computer system. Every device connected to a computer system is a resource. Every internal system component is a resource...
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 problem
Performance tuning
Performance tuning is the improvement of system performance. This is typically a computer application, but the same methods can be applied to economic markets, bureaucracies or other complex systems. The motivation for such activity is called a performance problem, which can be real or anticipated....
s or a crash
Crash (computing)
A crash in computing is a condition where a computer or a program, either an application or part of the operating system, ceases to function properly, often exiting after encountering errors. Often the offending program may appear to freeze or hang until a crash reporting service documents...
.
The term is derived from memory leak
Memory leak
A memory leak, in computer science , occurs when a computer program consumes memory but is unable to release it back to the operating system. In object-oriented programming, a memory leak happens when an object is stored in memory but cannot be accessed by the running code...
. Handle leaks, like memory leaks, are specific instances of resource leak
Resource leak
In computer science, a resource leak is a particular type of resource consumption by a computer program where the program cannot release resources it has acquired. This condition is normally the result of a bug in a program...
s.
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 referenceReference (computer science)
In computer science, a reference is a value that enables a program to indirectly access a particular data item, such as a variable or a record, in the computer's memory or in some other storage device. The reference is said to refer to the data item, and accessing those data is called...
, without understanding that a count, a copy, or other operation may actually be being performed.
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.