Fixed IDisposable implementation and usage.
- Implement IDisposable interface correctly, with sealed classes where possible for simplicity. - Add using statement around undisposed local variables.
This commit is contained in:
@@ -81,12 +81,11 @@ namespace OpenRA.Scripting
|
||||
public ScriptGlobalAttribute(string name) { Name = name; }
|
||||
}
|
||||
|
||||
public class ScriptContext : IDisposable
|
||||
public sealed class ScriptContext : IDisposable
|
||||
{
|
||||
public World World { get; private set; }
|
||||
public WorldRenderer WorldRenderer { get; private set; }
|
||||
|
||||
bool disposed;
|
||||
readonly MemoryConstrainedLuaRuntime runtime;
|
||||
readonly LuaFunction tick;
|
||||
|
||||
@@ -100,6 +99,8 @@ namespace OpenRA.Scripting
|
||||
public readonly Cache<ActorInfo, Type[]> ActorCommands;
|
||||
public readonly Type[] PlayerCommands;
|
||||
|
||||
bool disposed;
|
||||
|
||||
public ScriptContext(World world, WorldRenderer worldRenderer,
|
||||
IEnumerable<string> scripts)
|
||||
{
|
||||
@@ -196,27 +197,13 @@ namespace OpenRA.Scripting
|
||||
tick.Call().Dispose();
|
||||
}
|
||||
|
||||
protected void Dispose(bool disposing)
|
||||
public void Dispose()
|
||||
{
|
||||
if (disposed)
|
||||
return;
|
||||
|
||||
if (disposing)
|
||||
runtime.Dispose();
|
||||
|
||||
disposed = true;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
~ScriptContext()
|
||||
{
|
||||
// Dispose unmanaged resources only
|
||||
Dispose(false);
|
||||
if (runtime != null)
|
||||
runtime.Dispose();
|
||||
}
|
||||
|
||||
static Type[] ExtractRequiredTypes(Type t)
|
||||
|
||||
Reference in New Issue
Block a user