[1.0.0] The Dynamic Lifecycle - ntoxin66/Dynamic GitHub Wiki

A full example of a dynamic object life cycle

Dynamic dynamic = INVALID_DYNAMIC_OBJECT;

public void OnPluginStart()
{
	if (dynamic.IsValid) 
	{
		dynamic.Dispose();
		dynamic = INVALID_DYNAMIC_OBJECT;
	}
	dynamic = Dynamic();
}

public void OnPluginEnd()
{
	if (dynamic.IsValid) 
	{
		dynamic.Dispose();
		dynamic = INVALID_DYNAMIC_OBJECT;
	}
}

Into a finer grade of detail

At it's deepest level, Dynamic is an ArrayList where each index is a Dynamic instance.

Dynamic dynamic = Dynamic();

When we initialise a Dynamic instance as above, the dynamic variable represents an integer for it's index in the master ArrayList Collection. If you ever wanted to know the index you could do something like.

PrintToChatAll("> dynamic=%d", dynamic);

To check if a Dynamic instance is valid (not disposed) you can use the IsValid property.

if (dynamic.IsValid)
{
	// To something
}

Each initialised Dynamic instance requires at least two Handles. One is a StringMap for membername lookups and the other for an ArrayList where it's data is stored. As such, it's important to dispose every Dynamic instance when your done with it to free these Handles.

dynamic.Dispose();

Failure to dispose of your Dynamic instances can result in instance leaks that may decrease server performance or cause Sourcemod to unload Dynamic for having too many open Handles.

Next: Accessing Members