5.1 Handle

A handle is similar to a pointer in that it helps to locate an object that is dynamically allocated in memory. However, that is pretty much the end of the similarity.

First of all, a programming language that supports handles generates code to track handles. In other words, as execution enters a scope that defines a handle variable, the variable is “registered”. As execution leaves the scope, the variable (of handle type) is “unregistered”. This permits the language (interpreter or virtual machine) track active “reachable” handles from the program.

Next, a handle does not directly point to physical memory. There is one additional level of indirection. Consequently, it is possible to relocate objects allocated in dynamically allocate memory, and the reallocation does not break the linkage between the handles of the reallocated objects and the objects.

A handle can be implemented as an index into a large universal array of pointers. As a result, two handles referring to the same object are the same index into the same entry in the array of pointers. This also permits the change of the actual pointer in the array without impacting the handles.

A special requirement is that any class containing handles must place the handles in a special segment. This permits the interpreter or virtual machine inspect an object and track the objects that are referred to by this object.