Resource management (computing): Difference between revisions

Content deleted Content added
top: external memory
Line 1:
In [[computer programming]], '''resource management''' refers to techniques for managing [[System resource|resources]] (components with limited availability). It includes both preventing [[resource leak]]s (releasing a resource when a process has finished using it) and dealing with [[resource contention]] (when multiple processes wish to access a limited resource). Resource leaks are an issue in sequential computing, while resource contention is an issue in [[concurrent computing]]. This article discusses preventing resource leaks; see [[resource contention]] for resource management in that sense.
 
Memory can be treated as a resource, but [[memory management]] is usually considered separately, primarily because memory allocation and deallocation is significantly more frequent than acquisition and release of other resources, such as file handles.
 
[[Computer program]]s may manage their own resources, and there are various techniques for resource management, depending on the [[programming language]]; {{harvtxt|Elder|Jackson|Liblit|2008}} is a survey article contrasting different approaches. Alternatively, they can be managed by a host – an [[operating system]] or [[virtual machine]] – or another program. This is known as ''resource tracking,'' and consists of cleaning up resource leaks: terminating access to resources that have been acquired but not released after use. This is known as ''reclaiming'' resources, and is analogous to [[Garbage collection (computer science)|garbage collection]] for memory. On many systems the operating system reclaims resources after the process makes the [[exit (system call)|exit]] [[system call]].
 
Memory can be treated as a resource, but [[memory management]] is usually considered separately, primarily because memory allocation and deallocation is significantly more frequent than acquisition and release of other resources, such as file handles. Memory managed by an ''external'' system has similarities to both (internal) memory management (since it is memory) and resource management (since it is managed by an external system). Examples include memory managed via native code and used from Java (via [[Java Native Interface]]); and objects in the [[Document Object Model]] (DOM), used from [[JavaScript]]. In both these cases, the [[memory manager]] (garbage collector) of the [[runtime environment]] (virtual machine) is unable to manage the external memory (there is no shared memory management), and thus the external memory is treated as a resource, and managed analogously. However, cycles between systems (JavaScript referring to the DOM, referring back to JavaScript) can make management difficult or impossible.
 
A key distinction in resource management within a program is between ''stack management'' and ''heap management'' – whether a resource can be handled like a stack variable (lifetime is restricted to a single [[stack frame]], being acquired on entry to or within a particular scope, and released when execution exits that scope), or whether a resource must be handled like a heap variable, such as a resource acquired within a function and then returned from it, which must then be released outside of the acquiring function. Stack management is a common use case, and is significantly easier to handle than heap management.