Add missing PyObject.Dispose calls

- Adding _some_ of the missing PyObject.Dispose calls. In the cases
where C# is calling the Python side.
   - Note that Python calls to C# code is correctly handling the
   disposure of resources.
This commit is contained in:
Martin Molinero
2019-04-10 11:59:04 -03:00
parent 082906ed14
commit fa122fa809
17 changed files with 155 additions and 133 deletions
@@ -61,8 +61,8 @@ namespace QuantConnect.AlgorithmFactory.Python.Wrappers
Logging.Log.Trace($"AlgorithmPythonWrapper(): Python version {PythonEngine.Version}: Importing python module {moduleName}");
var module = Py.Import(moduleName);
foreach (var name in module.Dir())
var pyList = module.Dir();
foreach (var name in pyList)
{
Type type;
var attr = module.GetAttr(name.ToString());
@@ -90,8 +90,10 @@ namespace QuantConnect.AlgorithmFactory.Python.Wrappers
_onOrderEvent = (_algorithm as PyObject).GetAttr("OnOrderEvent");
}
attr.Dispose();
}
module.Dispose();
pyList.Dispose();
// If _algorithm could not be set, throw exception
if (_algorithm == null)
{