Class MemoryTracker
Generic service to manage shared objects and track the number of references to an object.
Inheritance
MemoryTracker
Syntax
public class MemoryTracker
Constructors
MemoryTracker(Clock.Proxy)
Declaration
public MemoryTracker(Clock.Proxy clock)
Parameters
Methods
Acquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey)
Increment the reference count on the specific resource without returning the
actual resource. This is useful in some scenario where the tracking count
does not directly depend on the caller having the resource directly in its hands
Declaration
public void Acquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key)
Parameters
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
AddAndAcquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey, TValue)
Add an item to the cache and increment the reference counter by 1.
Declaration
public void AddAndAcquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key, TValue value)
Parameters
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
ClearInactiveItems<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>)
Declaration
public void ClearInactiveItems<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle)
Parameters
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
ClearInactiveItemsOlderThan<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TimeSpan)
Declaration
public void ClearInactiveItemsOlderThan<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TimeSpan expirationTime)
Parameters
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
ContainsKey<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey)
Declaration
public bool ContainsKey<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key)
Parameters
Returns
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
CreateCache<TKey, TValue>(Action<TValue>)
Creates a key/value cache.
Declaration
public MemoryTracker.Handle<TKey, TValue> CreateCache<TKey, TValue>(Action<TValue> destructorFunc)
where TValue : class
Parameters
Type |
Name |
Description |
Action<TValue> |
destructorFunc |
The function called when the item is removed from the cache.
|
Returns
Type Parameters
Name |
Description |
TKey |
The key type.
|
TValue |
The value type.
|
DestroyCache<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>)
Destroy a key/value cache. Destroying a cache will call the destructor
function received when the cache was created for each object in the cache,
no matter if there are still active references on them.
Declaration
public void DestroyCache<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle)
Parameters
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
GetActiveItems<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>)
Declaration
public List<TValue> GetActiveItems<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle)
Parameters
Returns
Type |
Description |
List<TValue> |
|
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
GetInactiveItems<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>)
Declaration
public List<TValue> GetInactiveItems<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle)
Parameters
Returns
Type |
Description |
List<TValue> |
|
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
Release<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey)
Release a reference to the object associated with the key. If the reference
count drop to 0, the object is moved to a special buffer that can be cleared explicitly.
Declaration
public void Release<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key)
Parameters
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
ReleaseAndDestroy<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey)
Declaration
public void ReleaseAndDestroy<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key)
Parameters
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
Set<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey, TValue)
Declaration
public void Set<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key, TValue value)
Parameters
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
SetAndAcquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey, TValue)
Declaration
public void SetAndAcquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key, TValue value)
Parameters
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
TryAcquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey, out TValue)
Try to acquire a value in the cache from the key. WIll throw if the is invalid.
Declaration
public bool TryAcquire<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key, out TValue value)
Parameters
Returns
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
TryGetValue<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey, out TValue)
Tries to get a value from a key. This does not affect reference counting.
Declaration
public bool TryGetValue<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key, out TValue value)
Parameters
Returns
Type Parameters
Name |
Description |
TKey |
|
TValue |
|
TryRelease<TKey, TValue>(MemoryTracker.Handle<TKey, TValue>, TKey)
Declaration
public bool TryRelease<TKey, TValue>(MemoryTracker.Handle<TKey, TValue> handle, TKey key)
Parameters
Returns
Type Parameters
Name |
Description |
TKey |
|
TValue |
|