A system and method is provided for efficiently pinning references to the managed
heap. The system and method allow for references to managed objects to be declared
as pinned during a call to unmanaged code. The references are then reported as
pinned to a garbage collector in response to invocation of a garbage collection
service. The reference can be declared as pinned by a programmer within the source
code or automatically invoked at run-time based on an unsafe condition. The garbage
collection service will not move or relocate objects that are referenced by the
active pinned local variables. If a garbage collection does not occur, the fact
that the local variables are declared pinned is ignored.