Patent ID: 8095513

Claim:
A computer-implemented method, comprising: creating a safe buffer associated with a memory resource, the safe buffer created for a runtime agent executing in a managed execution environment; wrapping the memory resource with a wrapper, the wrapper including a counter, wherein a value of the counter indicates a number of threads that are using the safe buffer created for the runtime agent executing in the managed execution environment, and wherein the value of the counter is set to one upon creation of the safe buffer; upon determining that a thread is using the safe buffer, incrementing the value of the counter; upon determining that the thread is no longer using the safe buffer, decrementing the value of the counter; upon determining that the safe buffer has been disposed, setting the value of the counter to zero; receiving a request to access the memory resource; and determining whether to allow access to the memory resource in response to the request based on at least the value of the counter, wherein access to the memory resource is denied when the value of the counter is zero, a zero value indicating that the memory resource has been freed and is not safely accessible.